[Pytest-commit] commit/pytest: flub: Fix issue 336: autouse fixtures in plugins work again

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Thu Aug 1 19:58:38 CEST 2013


1 new commit in pytest:

https://bitbucket.org/hpk42/pytest/commits/34084c396adc/
Changeset:   34084c396adc
User:        flub
Date:        2013-08-01 19:58:28
Summary:     Fix issue 336: autouse fixtures in plugins work again

When an autouse fixture in a plugin was encountered None was stored as nodeid
where it used to be ''.  This broke the lookup of autouse fixtures later on.

This also adds another test for the normal fixture ordering which was slightly
wrong: a fixture without location was always added at the front of the fixture
list rather then at the end of the fixtures without location but before the
fixtures with location.
Affected #:  2 files

diff -r a5240a6c897a70ff55dc91d05e3f756af2004881 -r 34084c396adc9a79f43dfe7eadffb7f1f2ce7a7e _pytest/python.py
--- a/_pytest/python.py
+++ b/_pytest/python.py
@@ -1626,18 +1626,18 @@
                                     unittest=unittest)
             faclist = self._arg2fixturedefs.setdefault(name, [])
             if not fixturedef.has_location:
-                # All Nones are at the front so this inserts the
-                # current fixturedef after the existing fixturedefs
-                # from external plugins but before the fixturedefs
-                # provided in conftests.
-                i = faclist.count(None)
+                # All fixturedefs with no location are at the front
+                # so this inserts the current fixturedef after the
+                # existing fixturedefs from external plugins but
+                # before the fixturedefs provided in conftests.
+                i = len([f for f in faclist if not f.has_location])
             else:
                 i = len(faclist)  # append
             faclist.insert(i, fixturedef)
             if marker.autouse:
                 autousenames.append(name)
         if autousenames:
-            self._nodeid_and_autousenames.append((nodeid, autousenames))
+            self._nodeid_and_autousenames.append((nodeid or '', autousenames))
 
     def getfixturedefs(self, argname, nodeid):
         try:

diff -r a5240a6c897a70ff55dc91d05e3f756af2004881 -r 34084c396adc9a79f43dfe7eadffb7f1f2ce7a7e testing/python/fixture.py
--- a/testing/python/fixture.py
+++ b/testing/python/fixture.py
@@ -173,7 +173,7 @@
         result = testdir.runpytest(testfile)
         result.stdout.fnmatch_lines(["*1 passed*"])
 
-    def test_extend_fixture_conftest_plugin(request, testdir):
+    def test_extend_fixture_conftest_plugin(self, testdir):
         testdir.makepyfile(testplugin="""
             import pytest
 
@@ -198,6 +198,52 @@
         result = testdir.runpytest('-s')
         assert result.ret == 0
 
+    def test_extend_fixture_plugin_plugin(self, testdir):
+        # Two plugins should extend each order in loading order
+        testdir.makepyfile(testplugin0="""
+            import pytest
+
+            @pytest.fixture
+            def foo():
+                return 7
+        """)
+        testdir.makepyfile(testplugin1="""
+            import pytest
+
+            @pytest.fixture
+            def foo(foo):
+                return foo + 7
+        """)
+        testdir.syspathinsert()
+        testdir.makepyfile("""
+            pytest_plugins = ['testplugin0', 'testplugin1']
+
+            def test_foo(foo):
+                assert foo == 14
+        """)
+        result = testdir.runpytest()
+        assert result.ret == 0
+
+    def test_autouse_fixture_plugin(self, testdir):
+        # A fixture from a plugin has no baseid set, which screwed up
+        # the autouse fixture handling.
+        testdir.makepyfile(testplugin="""
+            import pytest
+
+            @pytest.fixture(autouse=True)
+            def foo(request):
+                request.function.foo = 7
+        """)
+        testdir.syspathinsert()
+        testdir.makepyfile("""
+            pytest_plugins = 'testplugin'
+
+            def test_foo(request):
+                assert request.function.foo == 7
+        """)
+        result = testdir.runpytest()
+        assert result.ret == 0
+
     def test_funcarg_lookup_error(self, testdir):
         p = testdir.makepyfile("""
             def test_lookup_error(unknown):

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.


More information about the pytest-commit mailing list