Skip to content

Commit

Permalink
Workaround issue with relpath on Windows. nedbat#895
Browse files Browse the repository at this point in the history
  • Loading branch information
ogrisel authored and nedbat committed Dec 19, 2019
1 parent 53ae55e commit c09c2c2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
9 changes: 8 additions & 1 deletion coverage/sqldata.py
Original file line number Diff line number Diff line change
Expand Up @@ -979,7 +979,14 @@ def _connect(self):
# 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
Expand Down

0 comments on commit c09c2c2

Please sign in to comment.