Strip invocation-scope suffix when displaying fixture lookup error
This commit is contained in:
parent
226f2795ba
commit
553dc2600f
|
@ -615,6 +615,16 @@ def scopemismatch(currentscope, newscope):
|
|||
return scopes.index(newscope) > scopes.index(currentscope)
|
||||
|
||||
|
||||
def strip_invocation_scope_suffix(name):
|
||||
"""Remove the invocation-scope suffix from the given name.
|
||||
|
||||
Invocation scope fixtures have their scope in the name of the fixture.
|
||||
For example, "monkeypatch:session". This function strips the suffix
|
||||
returning the user-frienldy name of the fixture.
|
||||
"""
|
||||
return name.split(':')[0]
|
||||
|
||||
|
||||
class FixtureLookupError(LookupError):
|
||||
""" could not return a requested Fixture (missing or invalid). """
|
||||
def __init__(self, argname, request, msg=None):
|
||||
|
@ -654,7 +664,8 @@ class FixtureLookupError(LookupError):
|
|||
parentid = self.request._pyfuncitem.parent.nodeid
|
||||
for name, fixturedefs in fm._arg2fixturedefs.items():
|
||||
faclist = list(fm._matchfactories(fixturedefs, parentid))
|
||||
if faclist:
|
||||
name = strip_invocation_scope_suffix(name)
|
||||
if faclist and name not in available:
|
||||
available.append(name)
|
||||
msg = "fixture %r not found" % (self.argname,)
|
||||
msg += "\n available fixtures: %s" %(", ".join(available),)
|
||||
|
|
|
@ -1006,6 +1006,7 @@ def showfixtures(config):
|
|||
|
||||
def _showfixtures_main(config, session):
|
||||
import _pytest.config
|
||||
from _pytest.fixtures import strip_invocation_scope_suffix
|
||||
session.perform_collect()
|
||||
curdir = py.path.local()
|
||||
tw = _pytest.config.create_terminal_writer(config)
|
||||
|
@ -1022,11 +1023,9 @@ def _showfixtures_main(config, session):
|
|||
continue
|
||||
for fixturedef in fixturedefs:
|
||||
loc = getlocation(fixturedef.func, curdir)
|
||||
fixture_argname = fixturedef.argname
|
||||
# invocation-scoped fixtures have argname in the form
|
||||
# "<name>:<scope>" (for example: "monkeypatch:session").
|
||||
if ':' in fixture_argname:
|
||||
fixture_argname = fixture_argname.split(':')[0]
|
||||
fixture_argname = strip_invocation_scope_suffix(fixturedef.argname)
|
||||
if (fixture_argname, loc) in seen:
|
||||
continue
|
||||
seen.add((fixture_argname, loc))
|
||||
|
|
|
@ -417,6 +417,7 @@ class TestFillFixtures:
|
|||
"*1 error*",
|
||||
])
|
||||
assert "INTERNAL" not in result.stdout.str()
|
||||
assert 'monkeypatch:session' not in result.stdout.str()
|
||||
|
||||
def test_fixture_excinfo_leak(self, testdir):
|
||||
# on python2 sys.excinfo would leak into fixture executions
|
||||
|
|
Loading…
Reference in New Issue