Skip to content

Commit 2051e30

Browse files
authored
Show fixture scopes with --fixtures, except for "function" scope (#5221)
Show fixture scopes with ``--fixtures``, except for "function" scope
2 parents 4a2fdce + 6d04037 commit 2051e30

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

changelog/5220.feature.rst

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
``--fixtures`` now also shows fixture scope for scopes other than ``"function"``.

src/_pytest/python.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -1342,17 +1342,19 @@ def _showfixtures_main(config, session):
13421342
currentmodule = module
13431343
if verbose <= 0 and argname[0] == "_":
13441344
continue
1345+
tw.write(argname, green=True)
1346+
if fixturedef.scope != "function":
1347+
tw.write(" [%s scope]" % fixturedef.scope, cyan=True)
13451348
if verbose > 0:
1346-
funcargspec = "%s -- %s" % (argname, bestrel)
1347-
else:
1348-
funcargspec = argname
1349-
tw.line(funcargspec, green=True)
1349+
tw.write(" -- %s" % bestrel, yellow=True)
1350+
tw.write("\n")
13501351
loc = getlocation(fixturedef.func, curdir)
13511352
doc = fixturedef.func.__doc__ or ""
13521353
if doc:
13531354
write_docstring(tw, doc)
13541355
else:
13551356
tw.line(" %s: no docstring available" % (loc,), red=True)
1357+
tw.line()
13561358

13571359

13581360
def write_docstring(tw, doc, indent=" "):

testing/python/fixtures.py

+16-2
Original file line numberDiff line numberDiff line change
@@ -3037,11 +3037,25 @@ def test_funcarg_compat(self, testdir):
30373037

30383038
def test_show_fixtures(self, testdir):
30393039
result = testdir.runpytest("--fixtures")
3040-
result.stdout.fnmatch_lines(["*tmpdir*", "*temporary directory*"])
3040+
result.stdout.fnmatch_lines(
3041+
[
3042+
"tmpdir_factory [[]session scope[]]",
3043+
"*for the test session*",
3044+
"tmpdir",
3045+
"*temporary directory*",
3046+
]
3047+
)
30413048

30423049
def test_show_fixtures_verbose(self, testdir):
30433050
result = testdir.runpytest("--fixtures", "-v")
3044-
result.stdout.fnmatch_lines(["*tmpdir*--*tmpdir.py*", "*temporary directory*"])
3051+
result.stdout.fnmatch_lines(
3052+
[
3053+
"tmpdir_factory [[]session scope[]] -- *tmpdir.py*",
3054+
"*for the test session*",
3055+
"tmpdir -- *tmpdir.py*",
3056+
"*temporary directory*",
3057+
]
3058+
)
30453059

30463060
def test_show_fixtures_testmodule(self, testdir):
30473061
p = testdir.makepyfile(

0 commit comments

Comments
 (0)