Skip to content

Commit b660ba6

Browse files
ogriselnedbat
authored andcommitted
Workaround issue with relpath on Windows
1 parent 53ae55e commit b660ba6

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

coverage/sqldata.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -979,7 +979,14 @@ def _connect(self):
979979
# SQLite on Windows on py2 won't open a file if the filename argument
980980
# has non-ascii characters in it. Opening a relative file name avoids
981981
# a problem if the current directory has non-ascii.
982-
filename = os.path.relpath(self.filename)
982+
try:
983+
filename = os.path.relpath(self.filename)
984+
except ValueError:
985+
# ValueError can be raised under Windows when os.getcwd() returns a
986+
# folder from a different drive than the drive of self.filename in
987+
# which case we keep the original value of self.filename unchanged,
988+
# hoping that we won't face the non-ascii directory problem.
989+
filename = self.filename
983990
# It can happen that Python switches threads while the tracer writes
984991
# data. The second thread will also try to write to the data,
985992
# effectively causing a nested context. However, given the idempotent

0 commit comments

Comments
 (0)