Merge pull request #4336 from blueyed/cwd2

Fix/improve handling of chdir with no-args and testpaths
This commit is contained in:
Daniel Hahler 2018-11-09 00:38:34 +01:00 committed by GitHub
commit 6c06057242
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 5 deletions

View File

@ -604,7 +604,6 @@ class Config(object):
self._warn = self.pluginmanager._warn self._warn = self.pluginmanager._warn
self.pluginmanager.register(self, "pytestconfig") self.pluginmanager.register(self, "pytestconfig")
self._configured = False self._configured = False
self.cwd = os.getcwd()
def do_setns(dic): def do_setns(dic):
import pytest import pytest
@ -847,10 +846,13 @@ class Config(object):
args, self.option, namespace=self.option args, self.option, namespace=self.option
) )
if not args: if not args:
if self.cwd == self.rootdir: if self.invocation_dir == self.rootdir:
args = self.getini("testpaths") args = [
str(self.invocation_dir.join(x, abs=True))
for x in self.getini("testpaths")
]
if not args: if not args:
args = [self.cwd] args = [str(self.invocation_dir)]
self.args = args self.args = args
except PrintHelp: except PrintHelp:
pass pass

View File

@ -1072,6 +1072,19 @@ def test_collect_with_chdir_during_import(testdir):
""" """
% (str(subdir),) % (str(subdir),)
) )
result = testdir.runpytest() with testdir.tmpdir.as_cwd():
result = testdir.runpytest()
result.stdout.fnmatch_lines(["*1 passed in*"]) result.stdout.fnmatch_lines(["*1 passed in*"])
assert result.ret == 0 assert result.ret == 0
# Handles relative testpaths.
testdir.makeini(
"""
[pytest]
testpaths = .
"""
)
with testdir.tmpdir.as_cwd():
result = testdir.runpytest("--collect-only")
result.stdout.fnmatch_lines(["collected 1 item"])
assert result.ret == 0