merge
This commit is contained in:
commit
ffa1bf726d
|
@ -1,6 +1,9 @@
|
|||
Changes between 2.3.5 and 2.4.DEV
|
||||
-----------------------------------
|
||||
|
||||
- fix issue300 - Fix order of conftest loading when starting py.test
|
||||
in a subdirectory.
|
||||
|
||||
- fix issue323 - sorting of many module-scoped arg parametrizations
|
||||
|
||||
- add support for setUpModule/tearDownModule detection, thanks Brian Okken.
|
||||
|
|
|
@ -196,27 +196,20 @@ class Conftest(object):
|
|||
self.getconftestmodules(x)
|
||||
|
||||
def getconftestmodules(self, path):
|
||||
""" return a list of imported conftest modules for the given path. """
|
||||
try:
|
||||
clist = self._path2confmods[path]
|
||||
except KeyError:
|
||||
if path is None:
|
||||
raise ValueError("missing default confest.")
|
||||
dp = path.dirpath()
|
||||
raise ValueError("missing default conftest.")
|
||||
clist = []
|
||||
if dp != path:
|
||||
cutdir = self._confcutdir
|
||||
if cutdir and path != cutdir and not path.relto(cutdir):
|
||||
pass
|
||||
else:
|
||||
conftestpath = path.join("conftest.py")
|
||||
if conftestpath.check(file=1):
|
||||
clist.append(self.importconftest(conftestpath))
|
||||
clist[:0] = self.getconftestmodules(dp)
|
||||
for parent in path.parts():
|
||||
if self._confcutdir and self._confcutdir.relto(parent):
|
||||
continue
|
||||
conftestpath = parent.join("conftest.py")
|
||||
if conftestpath.check(file=1):
|
||||
clist.append(self.importconftest(conftestpath))
|
||||
self._path2confmods[path] = clist
|
||||
# be defensive: avoid changes from caller side to
|
||||
# affect us by always returning a copy of the actual list
|
||||
return clist[:]
|
||||
return clist
|
||||
|
||||
def rget(self, name, path=None):
|
||||
mod, value = self.rget_with_confmod(name, path)
|
||||
|
|
|
@ -102,6 +102,77 @@ class TestFillFixtures:
|
|||
"*2 passed*"
|
||||
])
|
||||
|
||||
def test_extend_fixture_module_class(self, testdir):
|
||||
testfile = testdir.makepyfile("""
|
||||
import pytest
|
||||
|
||||
@pytest.fixture
|
||||
def spam():
|
||||
return 'spam'
|
||||
|
||||
class TestSpam:
|
||||
|
||||
@pytest.fixture
|
||||
def spam(self, spam):
|
||||
return spam * 2
|
||||
|
||||
def test_spam(self, spam):
|
||||
assert spam == 'spamspam'
|
||||
""")
|
||||
result = testdir.runpytest()
|
||||
result.stdout.fnmatch_lines(["*1 passed*"])
|
||||
result = testdir.runpytest(testfile)
|
||||
result.stdout.fnmatch_lines(["*1 passed*"])
|
||||
|
||||
def test_extend_fixture_conftest_module(self, testdir):
|
||||
testdir.makeconftest("""
|
||||
import pytest
|
||||
|
||||
@pytest.fixture
|
||||
def spam():
|
||||
return 'spam'
|
||||
""")
|
||||
testfile = testdir.makepyfile("""
|
||||
import pytest
|
||||
|
||||
@pytest.fixture
|
||||
def spam(spam):
|
||||
return spam * 2
|
||||
|
||||
def test_spam(spam):
|
||||
assert spam == 'spamspam'
|
||||
""")
|
||||
result = testdir.runpytest()
|
||||
result.stdout.fnmatch_lines(["*1 passed*"])
|
||||
result = testdir.runpytest(testfile)
|
||||
result.stdout.fnmatch_lines(["*1 passed*"])
|
||||
|
||||
def test_extend_fixture_conftest_conftest(self, testdir):
|
||||
testdir.makeconftest("""
|
||||
import pytest
|
||||
|
||||
@pytest.fixture
|
||||
def spam():
|
||||
return 'spam'
|
||||
""")
|
||||
pkg = testdir.mkpydir("pkg")
|
||||
pkg.join("conftest.py").write(py.code.Source("""
|
||||
import pytest
|
||||
|
||||
@pytest.fixture
|
||||
def spam(spam):
|
||||
return spam * 2
|
||||
"""))
|
||||
testfile = pkg.join("test_spam.py")
|
||||
testfile.write(py.code.Source("""
|
||||
def test_spam(spam):
|
||||
assert spam == "spamspam"
|
||||
"""))
|
||||
result = testdir.runpytest()
|
||||
result.stdout.fnmatch_lines(["*1 passed*"])
|
||||
result = testdir.runpytest(testfile)
|
||||
result.stdout.fnmatch_lines(["*1 passed*"])
|
||||
|
||||
def test_funcarg_lookup_error(self, testdir):
|
||||
p = testdir.makepyfile("""
|
||||
def test_lookup_error(unknown):
|
||||
|
|
|
@ -204,3 +204,14 @@ def test_conftest_confcutdir(testdir):
|
|||
"""))
|
||||
result = testdir.runpytest("-h", "--confcutdir=%s" % x, x)
|
||||
result.stdout.fnmatch_lines(["*--xyz*"])
|
||||
|
||||
def test_conftest_import_order(testdir, monkeypatch):
|
||||
ct1 = testdir.makeconftest("")
|
||||
sub = testdir.mkdir("sub")
|
||||
ct2 = sub.join("conftest.py")
|
||||
ct2.write("")
|
||||
def impct(p):
|
||||
return p
|
||||
conftest = Conftest()
|
||||
monkeypatch.setattr(conftest, 'importconftest', impct)
|
||||
assert conftest.getconftestmodules(sub) == [ct1, ct2]
|
||||
|
|
|
@ -654,9 +654,9 @@ def pytest_report_header(config, startdir):
|
|||
""")
|
||||
result = testdir.runpytest("a")
|
||||
result.stdout.fnmatch_lines([
|
||||
"*hello: 42*",
|
||||
"line1",
|
||||
str(testdir.tmpdir),
|
||||
"*hello: 42*",
|
||||
])
|
||||
|
||||
@pytest.mark.xfail("not hasattr(os, 'dup')")
|
||||
|
|
Loading…
Reference in New Issue