Skip to content

Commit

Permalink
Show fixture scopes with --fixtures, except for "function" scope
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoddemus committed May 6, 2019
1 parent 4a2fdce commit f6095b8
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
1 change: 1 addition & 0 deletions changelog/5220.feature.rst
@@ -0,0 +1 @@
``--fixtures`` now also shows fixture scope for scopes other than ``"function"``.
10 changes: 6 additions & 4 deletions src/_pytest/python.py
Expand Up @@ -1342,17 +1342,19 @@ def _showfixtures_main(config, session):
currentmodule = module
if verbose <= 0 and argname[0] == "_":
continue
tw.write(argname, green=True)
if fixturedef.scope != "function":
tw.write(" [%s scope]" % fixturedef.scope, cyan=True)
if verbose > 0:
funcargspec = "%s -- %s" % (argname, bestrel)
else:
funcargspec = argname
tw.line(funcargspec, green=True)
tw.write(" -- %s" % bestrel, yellow=True)
tw.write("\n")
loc = getlocation(fixturedef.func, curdir)
doc = fixturedef.func.__doc__ or ""
if doc:
write_docstring(tw, doc)
else:
tw.line(" %s: no docstring available" % (loc,), red=True)
tw.line()


def write_docstring(tw, doc, indent=" "):
Expand Down
18 changes: 16 additions & 2 deletions testing/python/fixtures.py
Expand Up @@ -3037,11 +3037,25 @@ def test_funcarg_compat(self, testdir):

def test_show_fixtures(self, testdir):
result = testdir.runpytest("--fixtures")
result.stdout.fnmatch_lines(["*tmpdir*", "*temporary directory*"])
result.stdout.fnmatch_lines(
[
"tmpdir_factory [[]session scope[]]",
"*for the test session*",
"tmpdir",
"*temporary directory*",
]
)

def test_show_fixtures_verbose(self, testdir):
result = testdir.runpytest("--fixtures", "-v")
result.stdout.fnmatch_lines(["*tmpdir*--*tmpdir.py*", "*temporary directory*"])
result.stdout.fnmatch_lines(
[
"tmpdir_factory [[]session scope[]] -- *tmpdir.py*",
"*for the test session*",
"tmpdir -- *tmpdir.py*",
"*temporary directory*",
]
)

def test_show_fixtures_testmodule(self, testdir):
p = testdir.makepyfile(
Expand Down

0 comments on commit f6095b8

Please sign in to comment.