From 41602b5ecfe602c53cef84fec249ed07dbd89538 Mon Sep 17 00:00:00 2001 From: Arthur Rio Date: Sat, 6 Aug 2022 13:06:25 -0600 Subject: fix: paths were wrong when running from root (#1403) * Fix paths when running coverage from root * Add simple tests * Use nested pattern for older python versions --- coverage/files.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'coverage/files.py') diff --git a/coverage/files.py b/coverage/files.py index 507496ff..b5895cfc 100644 --- a/coverage/files.py +++ b/coverage/files.py @@ -24,8 +24,14 @@ def set_relative_directory(): """Set the directory that `relative_filename` will be relative to.""" global RELATIVE_DIR, CANONICAL_FILENAME_CACHE + # The current directory + abs_curdir = abs_file(os.curdir) + if not abs_curdir.endswith(os.sep): + # Suffix with separator only if not at the system root + abs_curdir = abs_curdir + os.sep + # The absolute path to our current directory. - RELATIVE_DIR = os.path.normcase(abs_file(os.curdir) + os.sep) + RELATIVE_DIR = os.path.normcase(abs_curdir) # Cache of results of calling the canonical_filename() method, to # avoid duplicating work. -- cgit v1.2.1