@@ -1525,14 +1525,13 @@ def _ascii_escaped_by_config(val: Union[str, bytes], config: Optional[Config]) -
1525
1525
return val if escape_option else ascii_escaped (val ) # type: ignore
1526
1526
1527
1527
1528
- def _pretty_fixture_path (func ) -> str :
1529
- cwd = Path .cwd ()
1530
- loc = Path (getlocation (func , str (cwd )))
1528
+ def _pretty_fixture_path (invocation_dir : Path , func ) -> str :
1529
+ loc = Path (getlocation (func , invocation_dir ))
1531
1530
prefix = Path ("..." , "_pytest" )
1532
1531
try :
1533
1532
return str (prefix / loc .relative_to (_PYTEST_DIR ))
1534
1533
except ValueError :
1535
- return bestrelpath (cwd , loc )
1534
+ return bestrelpath (invocation_dir , loc )
1536
1535
1537
1536
1538
1537
def show_fixtures_per_test (config ):
@@ -1545,19 +1544,19 @@ def _show_fixtures_per_test(config: Config, session: Session) -> None:
1545
1544
import _pytest .config
1546
1545
1547
1546
session .perform_collect ()
1548
- curdir = Path . cwd ()
1547
+ invocation_dir = config . invocation_params . dir
1549
1548
tw = _pytest .config .create_terminal_writer (config )
1550
1549
verbose = config .getvalue ("verbose" )
1551
1550
1552
1551
def get_best_relpath (func ) -> str :
1553
- loc = getlocation (func , str ( curdir ) )
1554
- return bestrelpath (curdir , Path (loc ))
1552
+ loc = getlocation (func , invocation_dir )
1553
+ return bestrelpath (invocation_dir , Path (loc ))
1555
1554
1556
1555
def write_fixture (fixture_def : fixtures .FixtureDef [object ]) -> None :
1557
1556
argname = fixture_def .argname
1558
1557
if verbose <= 0 and argname .startswith ("_" ):
1559
1558
return
1560
- prettypath = _pretty_fixture_path (fixture_def .func )
1559
+ prettypath = _pretty_fixture_path (invocation_dir , fixture_def .func )
1561
1560
tw .write (f"{ argname } " , green = True )
1562
1561
tw .write (f" -- { prettypath } " , yellow = True )
1563
1562
tw .write ("\n " )
@@ -1601,7 +1600,7 @@ def _showfixtures_main(config: Config, session: Session) -> None:
1601
1600
import _pytest .config
1602
1601
1603
1602
session .perform_collect ()
1604
- curdir = Path . cwd ()
1603
+ invocation_dir = config . invocation_params . dir
1605
1604
tw = _pytest .config .create_terminal_writer (config )
1606
1605
verbose = config .getvalue ("verbose" )
1607
1606
@@ -1615,15 +1614,15 @@ def _showfixtures_main(config: Config, session: Session) -> None:
1615
1614
if not fixturedefs :
1616
1615
continue
1617
1616
for fixturedef in fixturedefs :
1618
- loc = getlocation (fixturedef .func , str ( curdir ) )
1617
+ loc = getlocation (fixturedef .func , invocation_dir )
1619
1618
if (fixturedef .argname , loc ) in seen :
1620
1619
continue
1621
1620
seen .add ((fixturedef .argname , loc ))
1622
1621
available .append (
1623
1622
(
1624
1623
len (fixturedef .baseid ),
1625
1624
fixturedef .func .__module__ ,
1626
- _pretty_fixture_path (fixturedef .func ),
1625
+ _pretty_fixture_path (invocation_dir , fixturedef .func ),
1627
1626
fixturedef .argname ,
1628
1627
fixturedef ,
1629
1628
)
0 commit comments