[Pytest-commit] commit/pytest: bubenkoff: Merged in conftest-nodeid (pull request #202)
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Mon Sep 15 13:04:12 CEST 2014
1 new commit in pytest:
https://bitbucket.org/hpk42/pytest/commits/a75e1258eed6/
Changeset: a75e1258eed6
User: bubenkoff
Date: 2014-09-15 13:04:07
Summary: Merged in conftest-nodeid (pull request #202)
fix conftest related fixture visibility issue
Affected #: 5 files
diff -r 2ae2ef6e63fc0f25ef44cca9d4c2ddcebd41ffc9 -r a75e1258eed60f5c7c648d9813a03ca6fd664406 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 a75e1258eed60f5c7c648d9813a03ca6fd664406 _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 a75e1258eed60f5c7c648d9813a03ca6fd664406 _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 a75e1258eed60f5c7c648d9813a03ca6fd664406 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 a75e1258eed60f5c7c648d9813a03ca6fd664406 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