3 new commits in pytest: https://bitbucket.org/hpk42/pytest/commits/1c51eba0e480/ Changeset: 1c51eba0e480 Branch: 320-class-scoped-fixture-caching-is-broken-if User: bubenkoff Date: 2013-07-06 21:30:24 Summary: re #320 fallback to test scope if the class-scoped fixture is used in non-class-based test function Affected #: 3 files
diff -r cc8871c02a5e4e34ad8e42121ffefb0651304b67 -r 1c51eba0e48065351d33a0087710dae4d49b768d _pytest/python.py --- a/_pytest/python.py +++ b/_pytest/python.py @@ -1317,7 +1317,8 @@ x = self._pyfuncitem.getparent(pytest.Class) if x is not None: return x - scope = "module" + # fallback to function + return self._pyfuncitem if scope == "module": return self._pyfuncitem.getparent(pytest.Module) raise ValueError("unknown finalization scope %r" %(scope,)) diff -r cc8871c02a5e4e34ad8e42121ffefb0651304b67 -r 1c51eba0e48065351d33a0087710dae4d49b768d testing/python/fixture.py --- a/testing/python/fixture.py +++ b/testing/python/fixture.py @@ -513,12 +513,12 @@ def test_request_cachedsetup_class(self, testdir): reprec = testdir.inline_runsource(""" - mysetup = ["hello", "hello2"].pop + mysetup = ["hello", "hello2", "hello3"].pop def pytest_funcarg__something(request): return request.cached_setup(mysetup, scope="class") def test_func1(something): - assert something == "hello2" + assert something == "hello3" def test_func2(something): assert something == "hello2" class TestClass: @@ -1090,7 +1090,7 @@ def arg(): l.append(1) return 0 - @pytest.fixture(scope="class", autouse=True) + @pytest.fixture(scope="module", autouse=True) def something(arg): l.append(2) diff -r cc8871c02a5e4e34ad8e42121ffefb0651304b67 -r 1c51eba0e48065351d33a0087710dae4d49b768d testing/test_fixture_scope.py --- /dev/null +++ b/testing/test_fixture_scope.py @@ -0,0 +1,28 @@ +"""Tests for fixtures with different scoping.""" + + +def test_class_scope_with_normal_tests(testdir): + testpath = testdir.makepyfile(""" + import pytest + + class Box: + value = 0 + + @pytest.fixture(scope='class') + def a(request): + Box.value += 1 + return Box.value + + def test_a(a): + assert a == 1 + + class Test1: + def test_b(self, a): + assert a == 2 + + class Test2: + def test_c(self, a): + assert a == 3""") + reprec = testdir.inline_run(testpath) + for test in ['test_a', 'test_b', 'test_c']: + assert reprec.matchreport(test).passed https://bitbucket.org/hpk42/pytest/commits/635c9c36e481/ Changeset: 635c9c36e481 Branch: 320-class-scoped-fixture-caching-is-broken-if User: hpk42 Date: 2013-07-08 15:45:07 Summary: Close branch 320-class-scoped-fixture-caching-is-broken-if Affected #: 0 files https://bitbucket.org/hpk42/pytest/commits/602a8ebee9ba/ Changeset: 602a8ebee9ba User: hpk42 Date: 2013-07-08 15:54:38 Summary: fix issue320 - fix class scope for fixtures when mixed with module-level functions. Thanks Anatloy Bubenkoff. Affected #: 5 files diff -r bcf6f8c25f89879da9dc994fec8320ad5d1912cc -r 602a8ebee9ba44b91699ad86426711f0aba35f7b AUTHORS --- a/AUTHORS +++ b/AUTHORS @@ -9,6 +9,7 @@ Jason R. Coombs Wouter van Ackooy Samuele Pedroni +Anatoly Bubenkoff Brianna Laugher Carl Friedrich Bolz Armin Rigo diff -r bcf6f8c25f89879da9dc994fec8320ad5d1912cc -r 602a8ebee9ba44b91699ad86426711f0aba35f7b CHANGELOG --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,9 @@ Changes between 2.3.5 and 2.4.DEV ----------------------------------- +- fix issue320 - fix class scope for fixtures when mixed with + module-level functions. Thanks Anatloy Bubenkoff. + - you can specify "-q" or "-qq" to get different levels of "quieter" reporting (thanks Katarzyna Jachim) diff -r bcf6f8c25f89879da9dc994fec8320ad5d1912cc -r 602a8ebee9ba44b91699ad86426711f0aba35f7b _pytest/python.py --- a/_pytest/python.py +++ b/_pytest/python.py @@ -1317,7 +1317,8 @@ x = self._pyfuncitem.getparent(pytest.Class) if x is not None: return x - scope = "module" + # fallback to function + return self._pyfuncitem if scope == "module": return self._pyfuncitem.getparent(pytest.Module) raise ValueError("unknown finalization scope %r" %(scope,)) diff -r bcf6f8c25f89879da9dc994fec8320ad5d1912cc -r 602a8ebee9ba44b91699ad86426711f0aba35f7b testing/python/fixture.py --- a/testing/python/fixture.py +++ b/testing/python/fixture.py @@ -513,12 +513,12 @@ def test_request_cachedsetup_class(self, testdir): reprec = testdir.inline_runsource(""" - mysetup = ["hello", "hello2"].pop + mysetup = ["hello", "hello2", "hello3"].pop def pytest_funcarg__something(request): return request.cached_setup(mysetup, scope="class") def test_func1(something): - assert something == "hello2" + assert something == "hello3" def test_func2(something): assert something == "hello2" class TestClass: @@ -1090,7 +1090,7 @@ def arg(): l.append(1) return 0 - @pytest.fixture(scope="class", autouse=True) + @pytest.fixture(scope="module", autouse=True) def something(arg): l.append(2) diff -r bcf6f8c25f89879da9dc994fec8320ad5d1912cc -r 602a8ebee9ba44b91699ad86426711f0aba35f7b testing/test_fixture_scope.py --- /dev/null +++ b/testing/test_fixture_scope.py @@ -0,0 +1,28 @@ +"""Tests for fixtures with different scoping.""" + + +def test_class_scope_with_normal_tests(testdir): + testpath = testdir.makepyfile(""" + import pytest + + class Box: + value = 0 + + @pytest.fixture(scope='class') + def a(request): + Box.value += 1 + return Box.value + + def test_a(a): + assert a == 1 + + class Test1: + def test_b(self, a): + assert a == 2 + + class Test2: + def test_c(self, a): + assert a == 3""") + reprec = testdir.inline_run(testpath) + for test in ['test_a', 'test_b', 'test_c']: + assert reprec.matchreport(test).passed Repository URL: https://bitbucket.org/hpk42/pytest/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email. _______________________________________________ pytest-commit mailing list pytest-commit@python.org http://mail.python.org/mailman/listinfo/pytest-commit