[Pytest-commit] commit/pytest: 2 new changesets
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Sat Apr 4 16:29:49 CEST 2015
2 new commits in pytest:
https://bitbucket.org/pytest-dev/pytest/commits/e419fe9ab7d4/
Changeset: e419fe9ab7d4
Branch: issue660
User: hpk42
Date: 2015-04-01 16:42:48+00:00
Summary: fix issue660: properly report fixture scope mismatches independent
from fixture argument ordering.
Affected #: 3 files
diff -r 0de3f5c1a683a834d27b265d5e8781326d5dad04 -r e419fe9ab7d4217782bf92ca7a04af6825563696 CHANGELOG
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,6 +1,11 @@
2.7.1.dev (compared to 2.7.0)
-----------------------------
+- fix issue660: properly report scope-mismatch-access errors
+ independently from ordering of fixture arguments. Also
+ avoid the pytest internal traceback which does not provide
+ information to the user.
+
2.7.0 (compared to 2.6.4)
-----------------------------
diff -r 0de3f5c1a683a834d27b265d5e8781326d5dad04 -r e419fe9ab7d4217782bf92ca7a04af6825563696 _pytest/python.py
--- a/_pytest/python.py
+++ b/_pytest/python.py
@@ -1356,12 +1356,7 @@
try:
val = cache[cachekey]
except KeyError:
- __tracebackhide__ = True
- if scopemismatch(self.scope, scope):
- raise ScopeMismatchError("You tried to access a %r scoped "
- "resource with a %r scoped request object" %(
- (scope, self.scope)))
- __tracebackhide__ = False
+ self._check_scope(self.fixturename, self.scope, scope)
val = setup()
cache[cachekey] = val
if teardown is not None:
@@ -1392,6 +1387,7 @@
if argname == "request":
class PseudoFixtureDef:
cached_result = (self, [0], None)
+ scope = "function"
return PseudoFixtureDef
raise
# remove indent to prevent the python3 exception
@@ -1435,16 +1431,7 @@
subrequest = SubRequest(self, scope, param, param_index, fixturedef)
# check if a higher-level scoped fixture accesses a lower level one
- if scope is not None:
- __tracebackhide__ = True
- if scopemismatch(self.scope, scope):
- # try to report something helpful
- lines = subrequest._factorytraceback()
- raise ScopeMismatchError("You tried to access the %r scoped "
- "fixture %r with a %r scoped request object, "
- "involved factories\n%s" %(
- (scope, argname, self.scope, "\n".join(lines))))
- __tracebackhide__ = False
+ subrequest._check_scope(argname, self.scope, scope)
# clear sys.exc_info before invoking the fixture (python bug?)
# if its not explicitly cleared it will leak into the call
@@ -1458,6 +1445,18 @@
subrequest.node)
return val
+ def _check_scope(self, argname, invoking_scope, requested_scope):
+ if argname == "request":
+ return
+ if scopemismatch(invoking_scope, requested_scope):
+ # try to report something helpful
+ lines = self._factorytraceback()
+ pytest.fail("ScopeMismatch: you tried to access the %r scoped "
+ "fixture %r with a %r scoped request object, "
+ "involved factories\n%s" %(
+ (requested_scope, argname, invoking_scope, "\n".join(lines))),
+ pytrace=False)
+
def _factorytraceback(self):
lines = []
for fixturedef in self._get_fixturestack():
@@ -1518,6 +1517,7 @@
def scopemismatch(currentscope, newscope):
return scopes.index(newscope) > scopes.index(currentscope)
+
class FixtureLookupError(LookupError):
""" could not return a requested Fixture (missing or invalid). """
def __init__(self, argname, request, msg=None):
@@ -1867,6 +1867,7 @@
for argname in self.argnames:
fixturedef = request._get_active_fixturedef(argname)
result, arg_cache_key, exc = fixturedef.cached_result
+ request._check_scope(argname, request.scope, fixturedef.scope)
kwargs[argname] = result
if argname != "request":
fixturedef.addfinalizer(self.finish)
diff -r 0de3f5c1a683a834d27b265d5e8781326d5dad04 -r e419fe9ab7d4217782bf92ca7a04af6825563696 testing/python/fixture.py
--- a/testing/python/fixture.py
+++ b/testing/python/fixture.py
@@ -906,6 +906,27 @@
"*1 error*"
])
+ def test_receives_funcargs_scope_mismatch_issue660(self, testdir):
+ testdir.makepyfile("""
+ import pytest
+ @pytest.fixture(scope="function")
+ def arg1():
+ return 1
+
+ @pytest.fixture(scope="module")
+ def arg2(arg1):
+ return arg1 + 1
+
+ def test_add(arg1, arg2):
+ assert arg2 == 2
+ """)
+ result = testdir.runpytest()
+ result.stdout.fnmatch_lines([
+ "*ScopeMismatch*involved factories*",
+ "* def arg2*",
+ "*1 error*"
+ ])
+
def test_funcarg_parametrized_and_used_twice(self, testdir):
testdir.makepyfile("""
import pytest
https://bitbucket.org/pytest-dev/pytest/commits/0b48b3b5156a/
Changeset: 0b48b3b5156a
Branch: pytest-2.7
User: hpk42
Date: 2015-04-04 14:29:38+00:00
Summary: add changelog entries
Affected #: 1 file
diff -r b872d84997379d9e140576d77516cf4d61f5347a -r 0b48b3b5156a55a09f3c27ce25beaeb156b56173 CHANGELOG
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -3,7 +3,10 @@
- streamlined and documented release process. Also all versions
(in setup.py and documentation generation) are now read
- from _pytest/__init__.py.
+ from _pytest/__init__.py. Thanks Holger Krekel.
+
+- fixed docs to remove the notion that yield-fixtures are experimental.
+ They are here to stay :) Thanks Bruno Oliveira.
2.7.0 (compared to 2.6.4)
-----------------------------
Repository URL: https://bitbucket.org/pytest-dev/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