Skip to content

Commit 6c06057

Browse files
authored
Merge pull request pytest-dev#4336 from blueyed/cwd2
Fix/improve handling of chdir with no-args and testpaths
2 parents 5dd509c + 3137c89 commit 6c06057

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

src/_pytest/config/__init__.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,6 @@ def __init__(self, pluginmanager):
604604
self._warn = self.pluginmanager._warn
605605
self.pluginmanager.register(self, "pytestconfig")
606606
self._configured = False
607-
self.cwd = os.getcwd()
608607

609608
def do_setns(dic):
610609
import pytest
@@ -847,10 +846,13 @@ def parse(self, args, addopts=True):
847846
args, self.option, namespace=self.option
848847
)
849848
if not args:
850-
if self.cwd == self.rootdir:
851-
args = self.getini("testpaths")
849+
if self.invocation_dir == self.rootdir:
850+
args = [
851+
str(self.invocation_dir.join(x, abs=True))
852+
for x in self.getini("testpaths")
853+
]
852854
if not args:
853-
args = [self.cwd]
855+
args = [str(self.invocation_dir)]
854856
self.args = args
855857
except PrintHelp:
856858
pass

testing/test_collection.py

+14-1
Original file line numberDiff line numberDiff line change
@@ -1072,6 +1072,19 @@ def test_1():
10721072
"""
10731073
% (str(subdir),)
10741074
)
1075-
result = testdir.runpytest()
1075+
with testdir.tmpdir.as_cwd():
1076+
result = testdir.runpytest()
10761077
result.stdout.fnmatch_lines(["*1 passed in*"])
10771078
assert result.ret == 0
1079+
1080+
# Handles relative testpaths.
1081+
testdir.makeini(
1082+
"""
1083+
[pytest]
1084+
testpaths = .
1085+
"""
1086+
)
1087+
with testdir.tmpdir.as_cwd():
1088+
result = testdir.runpytest("--collect-only")
1089+
result.stdout.fnmatch_lines(["collected 1 item"])
1090+
assert result.ret == 0

0 commit comments

Comments
 (0)