[Pytest-commit] commit/pytest: hpk42: fix conftest related fixture visibility issue: when running with a

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Mon Sep 15 12:44:29 CEST 2014


1 new commit in pytest:

https://bitbucket.org/hpk42/pytest/commits/4b8f938b224f/
Changeset:   4b8f938b224f
Branch:      conftest-nodeid
User:        hpk42
Date:        2014-09-15 12:44:16
Summary:     fix conftest related fixture visibility issue: when running with a
CWD outside a test package pytest would get fixture discovery wrong.
Thanks to Wolfgang Schnerring for figuring out a reproducable example.
Affected #:  5 files

diff -r 2ae2ef6e63fc0f25ef44cca9d4c2ddcebd41ffc9 -r 4b8f938b224f93005993113bd012598bfb898734 CHANGELOG
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -12,6 +12,10 @@
   instead of presuming any RuntimeError is that one (implemented in py
   dep).  Thanks Charles Cloud for analysing the issue.
 
+- fix conftest related fixture visibility issue: when running with a
+  CWD outside a test package pytest would get fixture discovery wrong.
+  Thanks to Wolfgang Schnerring for figuring out a reproducable example.
+
 
 2.6.2
 -----------

diff -r 2ae2ef6e63fc0f25ef44cca9d4c2ddcebd41ffc9 -r 4b8f938b224f93005993113bd012598bfb898734 _pytest/__init__.py
--- a/_pytest/__init__.py
+++ b/_pytest/__init__.py
@@ -1,2 +1,2 @@
 #
-__version__ = '2.6.3.dev'
+__version__ = '2.6.3.dev3'

diff -r 2ae2ef6e63fc0f25ef44cca9d4c2ddcebd41ffc9 -r 4b8f938b224f93005993113bd012598bfb898734 _pytest/python.py
--- a/_pytest/python.py
+++ b/_pytest/python.py
@@ -1611,10 +1611,15 @@
         except AttributeError:
             pass
         else:
+            # construct the base nodeid which is later used to check
+            # what fixtures are visible for particular tests (as denoted
+            # by their test id)
             if p.basename.startswith("conftest.py"):
-                nodeid = p.dirpath().relto(self.session.fspath)
+                nodeid = self.session.fspath.bestrelpath(p.dirpath())
                 if p.sep != "/":
                     nodeid = nodeid.replace(p.sep, "/")
+                if nodeid == ".":
+                    nodeid = ""
         self.parsefactories(plugin, nodeid)
         self._seenplugins.add(plugin)
 

diff -r 2ae2ef6e63fc0f25ef44cca9d4c2ddcebd41ffc9 -r 4b8f938b224f93005993113bd012598bfb898734 setup.py
--- a/setup.py
+++ b/setup.py
@@ -27,7 +27,7 @@
         name='pytest',
         description='pytest: simple powerful testing with Python',
         long_description=long_description,
-        version='2.6.3.dev',
+        version='2.6.3.dev3',
         url='http://pytest.org',
         license='MIT license',
         platforms=['unix', 'linux', 'osx', 'cygwin', 'win32'],

diff -r 2ae2ef6e63fc0f25ef44cca9d4c2ddcebd41ffc9 -r 4b8f938b224f93005993113bd012598bfb898734 testing/python/fixture.py
--- a/testing/python/fixture.py
+++ b/testing/python/fixture.py
@@ -1001,6 +1001,40 @@
         reprec = testdir.inline_run("-s")
         reprec.assertoutcome(passed=1)
 
+    def test_parsefactories_relative_node_ids(self, testdir):
+        # example mostly taken from:
+        # https://mail.python.org/pipermail/pytest-dev/2014-September/002617.html
+        runner = testdir.mkdir("runner")
+        package = testdir.mkdir("package")
+        package.join("conftest.py").write(dedent("""\
+            import pytest
+            @pytest.fixture
+            def one():
+                return 1
+        """))
+        package.join("test_x.py").write(dedent("""\
+            def test_x(one):
+                assert one == 1
+        """))
+        sub = package.mkdir("sub")
+        sub.join("__init__.py").ensure()
+        sub.join("conftest.py").write(dedent("""\
+            import pytest
+            @pytest.fixture
+            def one():
+                return 2
+        """))
+        sub.join("test_y.py").write(dedent("""\
+            def test_x(one):
+                assert one == 2
+        """))
+        reprec = testdir.inline_run()
+        reprec.assertoutcome(passed=2)
+        with runner.as_cwd():
+            reprec = testdir.inline_run("..")
+            reprec.assertoutcome(passed=2)
+
+
 class TestAutouseDiscovery:
     def pytest_funcarg__testdir(self, testdir):
         testdir.makeconftest("""

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