fix output of --fixtures for @pytest.fixture defined functions.
This commit is contained in:
parent
fb3af07ef4
commit
0594265adc
|
@ -1,2 +1,2 @@
|
||||||
#
|
#
|
||||||
__version__ = '2.3.0.dev20'
|
__version__ = '2.3.0.dev21'
|
||||||
|
|
|
@ -742,37 +742,45 @@ def showfixtures(config):
|
||||||
|
|
||||||
def _showfixtures_main(config, session):
|
def _showfixtures_main(config, session):
|
||||||
session.perform_collect()
|
session.perform_collect()
|
||||||
if session.items:
|
|
||||||
plugins = session.items[0].getplugins()
|
|
||||||
else:
|
|
||||||
plugins = session.getplugins()
|
|
||||||
curdir = py.path.local()
|
curdir = py.path.local()
|
||||||
|
if session.items:
|
||||||
|
nodeid = session.items[0].nodeid
|
||||||
|
else:
|
||||||
|
part = session._initialparts[0]
|
||||||
|
nodeid = "::".join(map(str, [curdir.bestrelpath(part[0])] + part[1:]))
|
||||||
|
|
||||||
tw = py.io.TerminalWriter()
|
tw = py.io.TerminalWriter()
|
||||||
verbose = config.getvalue("verbose")
|
verbose = config.getvalue("verbose")
|
||||||
argprefix = session._fixturemanager._argprefix
|
|
||||||
for plugin in plugins:
|
fm = session._fixturemanager
|
||||||
available = []
|
|
||||||
for name, factory in vars(plugin).items():
|
available = []
|
||||||
if name.startswith(argprefix):
|
for argname in fm.arg2fixturedeflist:
|
||||||
name = name[len(argprefix):]
|
fixturedeflist = fm.getfixturedeflist(argname, nodeid)
|
||||||
if name not in available:
|
assert fixturedeflist is not None
|
||||||
available.append([name, factory])
|
if not fixturedeflist:
|
||||||
if available:
|
continue
|
||||||
pluginname = plugin.__name__
|
fixturedef = fixturedeflist[-1]
|
||||||
for name, factory in available:
|
loc = getlocation(fixturedef.func, curdir)
|
||||||
loc = getlocation(factory, curdir)
|
available.append((len(fixturedef.baseid),
|
||||||
if verbose > 0:
|
curdir.bestrelpath(loc),
|
||||||
funcargspec = "%s -- %s" %(name, loc,)
|
fixturedef.argname, fixturedef))
|
||||||
else:
|
|
||||||
funcargspec = name
|
available.sort()
|
||||||
tw.line(funcargspec, green=True)
|
for baseid, bestrel, argname, fixturedef in available:
|
||||||
doc = factory.__doc__ or ""
|
if verbose > 0:
|
||||||
if doc:
|
funcargspec = "%s -- %s" %(name, loc,)
|
||||||
for line in doc.split("\n"):
|
else:
|
||||||
tw.line(" " + line.strip())
|
funcargspec = argname # "%s %s" %(baseid, argname)
|
||||||
else:
|
tw.line(funcargspec, green=True)
|
||||||
tw.line(" %s: no docstring available" %(loc,),
|
loc = getlocation(fixturedef.func, curdir)
|
||||||
red=True)
|
doc = fixturedef.func.__doc__ or ""
|
||||||
|
if doc:
|
||||||
|
for line in doc.split("\n"):
|
||||||
|
tw.line(" " + line.strip())
|
||||||
|
else:
|
||||||
|
tw.line(" %s: no docstring available" %(loc,),
|
||||||
|
red=True)
|
||||||
|
|
||||||
def getlocation(function, curdir):
|
def getlocation(function, curdir):
|
||||||
import inspect
|
import inspect
|
||||||
|
|
|
@ -43,7 +43,7 @@ install: html
|
||||||
rsync -avz _build/html/ pytest.org:/www/pytest.org/dev
|
rsync -avz _build/html/ pytest.org:/www/pytest.org/dev
|
||||||
|
|
||||||
installpdf: latexpdf
|
installpdf: latexpdf
|
||||||
@scp $(BUILDDIR)/latex/pytest.pdf pytest.org:/www/pytest.org/latest
|
@scp $(BUILDDIR)/latex/pytest.pdf pytest.org:/www/pytest.org/dev
|
||||||
|
|
||||||
installall: clean install installpdf
|
installall: clean install installpdf
|
||||||
@echo "done"
|
@echo "done"
|
||||||
|
|
2
setup.py
2
setup.py
|
@ -24,7 +24,7 @@ def main():
|
||||||
name='pytest',
|
name='pytest',
|
||||||
description='py.test: simple powerful testing with Python',
|
description='py.test: simple powerful testing with Python',
|
||||||
long_description = long_description,
|
long_description = long_description,
|
||||||
version='2.3.0.dev20',
|
version='2.3.0.dev21',
|
||||||
url='http://pytest.org',
|
url='http://pytest.org',
|
||||||
license='MIT license',
|
license='MIT license',
|
||||||
platforms=['unix', 'linux', 'osx', 'cygwin', 'win32'],
|
platforms=['unix', 'linux', 'osx', 'cygwin', 'win32'],
|
||||||
|
|
|
@ -1515,13 +1515,50 @@ class TestReportInfo:
|
||||||
pass
|
pass
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def test_show_funcarg(testdir):
|
class TestShowFixtures:
|
||||||
result = testdir.runpytest("--fixtures")
|
def test_show_fixtures(self, testdir):
|
||||||
result.stdout.fnmatch_lines([
|
result = testdir.runpytest("--fixtures")
|
||||||
"*tmpdir*",
|
result.stdout.fnmatch_lines([
|
||||||
"*temporary directory*",
|
"*tmpdir*",
|
||||||
]
|
"*temporary directory*",
|
||||||
)
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_show_fixtures_testmodule(self, testdir):
|
||||||
|
p = testdir.makepyfile('''
|
||||||
|
import pytest
|
||||||
|
@pytest.fixture
|
||||||
|
def arg1():
|
||||||
|
""" hello world """
|
||||||
|
''')
|
||||||
|
result = testdir.runpytest("--fixtures", p)
|
||||||
|
result.stdout.fnmatch_lines("""
|
||||||
|
*tmpdir*
|
||||||
|
*arg1*
|
||||||
|
*hello world*
|
||||||
|
""")
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("testmod", [True, False])
|
||||||
|
def test_show_fixtures_conftest(self, testdir, testmod):
|
||||||
|
testdir.makeconftest('''
|
||||||
|
import pytest
|
||||||
|
@pytest.fixture
|
||||||
|
def arg1():
|
||||||
|
""" hello world """
|
||||||
|
''')
|
||||||
|
if testmod:
|
||||||
|
testdir.makepyfile("""
|
||||||
|
def test_hello():
|
||||||
|
pass
|
||||||
|
""")
|
||||||
|
result = testdir.runpytest("--fixtures")
|
||||||
|
result.stdout.fnmatch_lines("""
|
||||||
|
*tmpdir*
|
||||||
|
*arg1*
|
||||||
|
*hello world*
|
||||||
|
""")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class TestRaises:
|
class TestRaises:
|
||||||
def test_raises(self):
|
def test_raises(self):
|
||||||
|
|
Loading…
Reference in New Issue