Skip to content

Commit

Permalink
add colour encoding to fixture location paths
Browse files Browse the repository at this point in the history
  • Loading branch information
kumiDa committed May 6, 2021
1 parent 58529b4 commit 5007871
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
15 changes: 9 additions & 6 deletions src/_pytest/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -1429,11 +1429,14 @@ def write_fixture(fixture_def: fixtures.FixtureDef[object]) -> None:
if verbose <= 0 and argname.startswith("_"):
return
bestrel = get_best_relpath(fixture_def.func)
funcargspec = f"{argname} -- {bestrel}"
tw.line(funcargspec, green=True)
tw.write(f"{argname}", green=True)
tw.write(f" -- {bestrel}", yellow=True)
tw.write("\n")
fixture_doc = inspect.getdoc(fixture_def.func)
if fixture_doc:
write_docstring(tw, fixture_doc.split("\n\n")[0] if verbose<=0 else fixture_doc)
write_docstring(
tw, fixture_doc.split("\n\n")[0] if verbose <= 0 else fixture_doc
)
else:
tw.line(" no docstring available", red=True)

Expand Down Expand Up @@ -1507,15 +1510,15 @@ def _showfixtures_main(config: Config, session: Session) -> None:
currentmodule = module
if verbose <= 0 and argname.startswith("_"):
continue
funcargspec = f"{argname} -- {bestrel}"
tw.write(funcargspec, green=True)
tw.write(f"{argname}", green=True)
if fixturedef.scope != "function":
tw.write(" [%s scope]" % fixturedef.scope, cyan=True)
tw.write(f" -- {bestrel}", yellow=True)
tw.write("\n")
loc = getlocation(fixturedef.func, str(curdir))
doc = inspect.getdoc(fixturedef.func)
if doc:
write_docstring(tw, doc.split("\n\n")[0] if verbose<=0 else doc)
write_docstring(tw, doc.split("\n\n")[0] if verbose <= 0 else doc)
else:
tw.line(f" {loc}: no docstring available", red=True)
tw.line()
Expand Down
4 changes: 2 additions & 2 deletions testing/python/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -3334,7 +3334,7 @@ def test_show_fixtures(self, pytester: Pytester) -> None:
result = pytester.runpytest("--fixtures")
result.stdout.fnmatch_lines(
[
"tmp_path_factory -- *[[]session scope[]]",
"tmp_path_factory [[]session scope[]] -- *tmpdir.py*",
"*for the test session*",
"tmp_path -- *",
"*temporary directory*",
Expand All @@ -3345,7 +3345,7 @@ def test_show_fixtures_verbose(self, pytester: Pytester) -> None:
result = pytester.runpytest("--fixtures", "-v")
result.stdout.fnmatch_lines(
[
"tmp_path_factory -- *tmpdir.py* [[]session scope[]]",
"tmp_path_factory [[]session scope[]] -- *tmpdir.py*",
"*for the test session*",
"tmp_path -- *tmpdir.py*",
"*temporary directory*",
Expand Down
12 changes: 7 additions & 5 deletions testing/python/show_fixtures_per_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def test_arg1(arg1):
"*fixtures used by test_arg1*",
"*(test_fixtures_in_module.py:9)*",
"arg1 -- test_fixtures_in_module.py:6",
" arg1 docstring"
" arg1 docstring",
]
)
result.stdout.no_fnmatch_line("*_arg0*")
Expand Down Expand Up @@ -181,6 +181,7 @@ def foo():

result.stdout.fnmatch_lines(["*collected 2 items*"])


def test_multiline_docstring_in_module(pytester: Pytester) -> None:
p = pytester.makepyfile(
'''
Expand All @@ -190,9 +191,9 @@ def arg1():
"""Docstring content that spans across multiple lines,
through second line,
and through third line.
Docstring content that extends into a second paragraph.
Docstring content that extends into a third paragraph.
"""
def test_arg1(arg1):
Expand All @@ -210,10 +211,11 @@ def test_arg1(arg1):
"arg1 -- test_multiline_docstring_in_module.py:3",
" Docstring content that spans across multiple lines,",
" through second line,",
" and through third line."
" and through third line.",
]
)


def test_verbose_include_multiline_docstring(pytester: Pytester) -> None:
p = pytester.makepyfile(
'''
Expand Down Expand Up @@ -247,6 +249,6 @@ def test_arg1(arg1):
" ",
" Docstring content that extends into a second paragraph.",
" ",
" Docstring content that extends into a third paragraph."
" Docstring content that extends into a third paragraph.",
]
)

0 comments on commit 5007871

Please sign in to comment.