8383 from _pytest .scope import _ScopeName
8484
8585
86+ _PYTEST_DIR = Path (_pytest .__file__ ).parent
87+
88+
8689def pytest_addoption (parser : Parser ) -> None :
8790 group = parser .getgroup ("general" )
8891 group .addoption (
@@ -1443,6 +1446,16 @@ def idmaker(
14431446 return resolved_ids
14441447
14451448
1449+ def _pretty_fixture_path (func ) -> str :
1450+ cwd = Path .cwd ()
1451+ loc = Path (getlocation (func , str (cwd )))
1452+ prefix = Path ("..." , "_pytest" )
1453+ try :
1454+ return str (prefix / loc .relative_to (_PYTEST_DIR ))
1455+ except ValueError :
1456+ return bestrelpath (cwd , loc )
1457+
1458+
14461459def show_fixtures_per_test (config ):
14471460 from _pytest .main import wrap_session
14481461
@@ -1465,9 +1478,9 @@ def write_fixture(fixture_def: fixtures.FixtureDef[object]) -> None:
14651478 argname = fixture_def .argname
14661479 if verbose <= 0 and argname .startswith ("_" ):
14671480 return
1468- bestrel = get_best_relpath (fixture_def .func )
1481+ prettypath = _pretty_fixture_path (fixture_def .func )
14691482 tw .write (f"{ argname } " , green = True )
1470- tw .write (f" -- { bestrel } " , yellow = True )
1483+ tw .write (f" -- { prettypath } " , yellow = True )
14711484 tw .write ("\n " )
14721485 fixture_doc = inspect .getdoc (fixture_def .func )
14731486 if fixture_doc :
@@ -1531,15 +1544,15 @@ def _showfixtures_main(config: Config, session: Session) -> None:
15311544 (
15321545 len (fixturedef .baseid ),
15331546 fixturedef .func .__module__ ,
1534- bestrelpath ( curdir , Path ( loc ) ),
1547+ _pretty_fixture_path ( fixturedef . func ),
15351548 fixturedef .argname ,
15361549 fixturedef ,
15371550 )
15381551 )
15391552
15401553 available .sort ()
15411554 currentmodule = None
1542- for baseid , module , bestrel , argname , fixturedef in available :
1555+ for baseid , module , prettypath , argname , fixturedef in available :
15431556 if currentmodule != module :
15441557 if not module .startswith ("_pytest." ):
15451558 tw .line ()
@@ -1550,14 +1563,13 @@ def _showfixtures_main(config: Config, session: Session) -> None:
15501563 tw .write (f"{ argname } " , green = True )
15511564 if fixturedef .scope != "function" :
15521565 tw .write (" [%s scope]" % fixturedef .scope , cyan = True )
1553- tw .write (f" -- { bestrel } " , yellow = True )
1566+ tw .write (f" -- { prettypath } " , yellow = True )
15541567 tw .write ("\n " )
1555- loc = getlocation (fixturedef .func , str (curdir ))
15561568 doc = inspect .getdoc (fixturedef .func )
15571569 if doc :
15581570 write_docstring (tw , doc .split ("\n \n " )[0 ] if verbose <= 0 else doc )
15591571 else :
1560- tw .line (f " { loc } : no docstring available" , red = True )
1572+ tw .line (" no docstring available" , red = True )
15611573 tw .line ()
15621574
15631575
0 commit comments