Merge pull request #4336 from blueyed/cwd2
Fix/improve handling of chdir with no-args and testpaths
This commit is contained in:
commit
6c06057242
|
@ -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
|
||||||
|
|
|
@ -1072,6 +1072,19 @@ def test_collect_with_chdir_during_import(testdir):
|
||||||
"""
|
"""
|
||||||
% (str(subdir),)
|
% (str(subdir),)
|
||||||
)
|
)
|
||||||
|
with testdir.tmpdir.as_cwd():
|
||||||
result = testdir.runpytest()
|
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
|
||||||
|
|
Loading…
Reference in New Issue