summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOlivier Grisel <olivier.grisel@ensta.org>2019-12-18 12:43:34 +0100
committerNed Batchelder <ned@nedbatchelder.com>2019-12-19 06:05:39 -0500
commitc09c2c203286db3cae1148bd02b1db9a9d524af1 (patch)
treebc155ceaa51ac2cf1c0db5f2a66275e89b191a63
parent53ae55e053a4e7358a5708b2c194d26851690439 (diff)
downloadpython-coveragepy-git-c09c2c203286db3cae1148bd02b1db9a9d524af1.tar.gz
Workaround issue with relpath on Windows. #895
-rw-r--r--CHANGES.rst4
-rw-r--r--coverage/sqldata.py9
2 files changed, 12 insertions, 1 deletions
diff --git a/CHANGES.rst b/CHANGES.rst
index 0c426023..84672e28 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -29,7 +29,11 @@ Unreleased
process' file with no suffix when using ``--append``. This is now fixed,
closing `issue 880`_.
+- Fixed a problem on Windows when the current directory is changed to a
+ different drive (`issue 895`_). Thanks, Olivier Grisel.
+
.. _issue 880: https://github.com/nedbat/coveragepy/issues/880
+.. _issue 895: https://github.com/nedbat/coveragepy/issues/895
.. _changes_50:
diff --git a/coverage/sqldata.py b/coverage/sqldata.py
index 56468e64..01f5ce01 100644
--- a/coverage/sqldata.py
+++ b/coverage/sqldata.py
@@ -979,7 +979,14 @@ class SqliteDb(SimpleReprMixin):
# SQLite on Windows on py2 won't open a file if the filename argument
# has non-ascii characters in it. Opening a relative file name avoids
# a problem if the current directory has non-ascii.
- filename = os.path.relpath(self.filename)
+ try:
+ filename = os.path.relpath(self.filename)
+ except ValueError:
+ # ValueError can be raised under Windows when os.getcwd() returns a
+ # folder from a different drive than the drive of self.filename in
+ # which case we keep the original value of self.filename unchanged,
+ # hoping that we won't face the non-ascii directory problem.
+ filename = self.filename
# It can happen that Python switches threads while the tracer writes
# data. The second thread will also try to write to the data,
# effectively causing a nested context. However, given the idempotent