83
83
from _pytest .scope import _ScopeName
84
84
85
85
86
+ _PYTEST_DIR = Path (_pytest .__file__ ).parent
87
+
88
+
86
89
def pytest_addoption (parser : Parser ) -> None :
87
90
group = parser .getgroup ("general" )
88
91
group .addoption (
@@ -1443,6 +1446,16 @@ def idmaker(
1443
1446
return resolved_ids
1444
1447
1445
1448
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
+
1446
1459
def show_fixtures_per_test (config ):
1447
1460
from _pytest .main import wrap_session
1448
1461
@@ -1465,9 +1478,9 @@ def write_fixture(fixture_def: fixtures.FixtureDef[object]) -> None:
1465
1478
argname = fixture_def .argname
1466
1479
if verbose <= 0 and argname .startswith ("_" ):
1467
1480
return
1468
- bestrel = get_best_relpath (fixture_def .func )
1481
+ prettypath = _pretty_fixture_path (fixture_def .func )
1469
1482
tw .write (f"{ argname } " , green = True )
1470
- tw .write (f" -- { bestrel } " , yellow = True )
1483
+ tw .write (f" -- { prettypath } " , yellow = True )
1471
1484
tw .write ("\n " )
1472
1485
fixture_doc = inspect .getdoc (fixture_def .func )
1473
1486
if fixture_doc :
@@ -1531,15 +1544,15 @@ def _showfixtures_main(config: Config, session: Session) -> None:
1531
1544
(
1532
1545
len (fixturedef .baseid ),
1533
1546
fixturedef .func .__module__ ,
1534
- bestrelpath ( curdir , Path ( loc ) ),
1547
+ _pretty_fixture_path ( fixturedef . func ),
1535
1548
fixturedef .argname ,
1536
1549
fixturedef ,
1537
1550
)
1538
1551
)
1539
1552
1540
1553
available .sort ()
1541
1554
currentmodule = None
1542
- for baseid , module , bestrel , argname , fixturedef in available :
1555
+ for baseid , module , prettypath , argname , fixturedef in available :
1543
1556
if currentmodule != module :
1544
1557
if not module .startswith ("_pytest." ):
1545
1558
tw .line ()
@@ -1550,14 +1563,13 @@ def _showfixtures_main(config: Config, session: Session) -> None:
1550
1563
tw .write (f"{ argname } " , green = True )
1551
1564
if fixturedef .scope != "function" :
1552
1565
tw .write (" [%s scope]" % fixturedef .scope , cyan = True )
1553
- tw .write (f" -- { bestrel } " , yellow = True )
1566
+ tw .write (f" -- { prettypath } " , yellow = True )
1554
1567
tw .write ("\n " )
1555
- loc = getlocation (fixturedef .func , str (curdir ))
1556
1568
doc = inspect .getdoc (fixturedef .func )
1557
1569
if doc :
1558
1570
write_docstring (tw , doc .split ("\n \n " )[0 ] if verbose <= 0 else doc )
1559
1571
else :
1560
- tw .line (f" { loc } : no docstring available" , red = True )
1572
+ tw .line (f" no docstring available" , red = True )
1561
1573
tw .line ()
1562
1574
1563
1575
0 commit comments