improve --fixtures output with per-plugin grouping and hiding underscore names in non-verbose mode, re-introduce --funcargs for compatibiliy
This commit is contained in:
parent
51644a116c
commit
20849a44f5
|
@ -1,2 +1,2 @@
|
|||
#
|
||||
__version__ = '2.3.0.dev25'
|
||||
__version__ = '2.3.0.dev26'
|
||||
|
|
|
@ -65,7 +65,7 @@ def pyobj_property(name):
|
|||
|
||||
def pytest_addoption(parser):
|
||||
group = parser.getgroup("general")
|
||||
group.addoption('--fixtures', '--fixtures',
|
||||
group.addoption('--fixtures', '--funcargs',
|
||||
action="store_true", dest="showfixtures", default=False,
|
||||
help="show available fixtures, sorted by plugin appearance")
|
||||
parser.addini("usefixtures", type="args", default=[],
|
||||
|
@ -746,15 +746,24 @@ def _showfixtures_main(config, session):
|
|||
fixturedef = fixturedefs[-1]
|
||||
loc = getlocation(fixturedef.func, curdir)
|
||||
available.append((len(fixturedef.baseid),
|
||||
fixturedef.func.__module__,
|
||||
curdir.bestrelpath(loc),
|
||||
fixturedef.argname, fixturedef))
|
||||
|
||||
available.sort()
|
||||
for baseid, bestrel, argname, fixturedef in available:
|
||||
currentmodule = None
|
||||
for baseid, module, bestrel, argname, fixturedef in available:
|
||||
if currentmodule != module:
|
||||
if not module.startswith("_pytest."):
|
||||
tw.line()
|
||||
tw.sep("-", "fixtures defined from %s" %(module,))
|
||||
currentmodule = module
|
||||
if verbose <= 0 and argname[0] == "_":
|
||||
continue
|
||||
if verbose > 0:
|
||||
funcargspec = "%s -- %s" %(name, loc,)
|
||||
funcargspec = "%s -- %s" %(argname, loc,)
|
||||
else:
|
||||
funcargspec = argname # "%s %s" %(baseid, argname)
|
||||
funcargspec = argname
|
||||
tw.line(funcargspec, green=True)
|
||||
loc = getlocation(fixturedef.func, curdir)
|
||||
doc = fixturedef.func.__doc__ or ""
|
||||
|
|
2
setup.py
2
setup.py
|
@ -24,7 +24,7 @@ def main():
|
|||
name='pytest',
|
||||
description='py.test: simple powerful testing with Python',
|
||||
long_description = long_description,
|
||||
version='2.3.0.dev25',
|
||||
version='2.3.0.dev26',
|
||||
url='http://pytest.org',
|
||||
license='MIT license',
|
||||
platforms=['unix', 'linux', 'osx', 'cygwin', 'win32'],
|
||||
|
|
|
@ -1575,6 +1575,10 @@ class TestReportInfo:
|
|||
"""
|
||||
|
||||
class TestShowFixtures:
|
||||
def test_funcarg_compat(self, testdir):
|
||||
config = testdir.parseconfigure("--funcargs")
|
||||
assert config.option.showfixtures
|
||||
|
||||
def test_show_fixtures(self, testdir):
|
||||
result = testdir.runpytest("--fixtures")
|
||||
result.stdout.fnmatch_lines([
|
||||
|
@ -1583,19 +1587,32 @@ class TestShowFixtures:
|
|||
]
|
||||
)
|
||||
|
||||
def test_show_fixtures_verbose(self, testdir):
|
||||
result = testdir.runpytest("--fixtures", "-v")
|
||||
result.stdout.fnmatch_lines([
|
||||
"*tmpdir*",
|
||||
"*temporary directory*",
|
||||
]
|
||||
)
|
||||
|
||||
def test_show_fixtures_testmodule(self, testdir):
|
||||
p = testdir.makepyfile('''
|
||||
import pytest
|
||||
@pytest.fixture
|
||||
def _arg0():
|
||||
""" hidden """
|
||||
@pytest.fixture
|
||||
def arg1():
|
||||
""" hello world """
|
||||
''')
|
||||
result = testdir.runpytest("--fixtures", p)
|
||||
result.stdout.fnmatch_lines("""
|
||||
*tmpdir*
|
||||
*tmpdir
|
||||
*fixtures defined from*
|
||||
*arg1*
|
||||
*hello world*
|
||||
""")
|
||||
assert "arg0" not in result.stdout.str()
|
||||
|
||||
@pytest.mark.parametrize("testmod", [True, False])
|
||||
def test_show_fixtures_conftest(self, testdir, testmod):
|
||||
|
@ -1613,6 +1630,7 @@ class TestShowFixtures:
|
|||
result = testdir.runpytest("--fixtures")
|
||||
result.stdout.fnmatch_lines("""
|
||||
*tmpdir*
|
||||
*fixtures defined from*conftest*
|
||||
*arg1*
|
||||
*hello world*
|
||||
""")
|
||||
|
|
Loading…
Reference in New Issue