@@ -1308,13 +1308,16 @@ def test_rootpath_base(self, pytester: Pytester, monkeypatch: MonkeyPatch) -> No
1308
1308
from _pytest .assertion import AssertionState
1309
1309
1310
1310
config = pytester .parseconfig ()
1311
- monkeypatch .chdir (pytester .path )
1312
1311
state = AssertionState (config , "rewrite" )
1313
- assert state .rootpath == str (pytester . path )
1314
- new_rootpath = str (pytester .path ) + "/ test"
1312
+ assert state .rootpath == str (config . invocation_params . dir )
1313
+ new_rootpath = str (pytester .path / " test")
1315
1314
if not os .path .exists (new_rootpath ):
1316
1315
os .mkdir (new_rootpath )
1317
- monkeypatch .chdir (new_rootpath )
1316
+ monkeypatch .setattr (config ,"invocation_params" , Config .InvocationParams (
1317
+ args = (),
1318
+ plugins = (),
1319
+ dir = Path (new_rootpath ),
1320
+ ))
1318
1321
state = AssertionState (config , "rewrite" )
1319
1322
assert state .rootpath == new_rootpath
1320
1323
@@ -1324,20 +1327,6 @@ def test_rootpath_base(self, pytester: Pytester, monkeypatch: MonkeyPatch) -> No
1324
1327
@pytest .mark .skipif (
1325
1328
sys .platform .startswith ("sunos5" ), reason = "cannot remove cwd on Solaris"
1326
1329
)
1327
- def test_rootpath_cwd_removed (
1328
- self , pytester : Pytester , monkeypatch : MonkeyPatch
1329
- ) -> None :
1330
- # Setup conditions for py's trying to os.getcwd() on py34
1331
- # when current working directory doesn't exist (previously triggered via xdist only).
1332
- # Ref: https://github.com/pytest-dev/py/pull/207
1333
- from _pytest .assertion import AssertionState
1334
-
1335
- config = pytester .parseconfig ()
1336
- monkeypatch .setattr (
1337
- target = os , name = "getcwd" , value = Mock (side_effect = FileNotFoundError )
1338
- )
1339
- state = AssertionState (config , "rewrite" )
1340
- assert state .rootpath == os .path .abspath (os .sep )
1341
1330
1342
1331
def test_write_pyc (self , pytester : Pytester , tmp_path ) -> None :
1343
1332
from _pytest .assertion import AssertionState
@@ -2036,7 +2025,11 @@ def test_simple_failure():
2036
2025
rootpath = f"{ os .getcwd ()} /tests"
2037
2026
if not os .path .exists (rootpath ):
2038
2027
mkdir (rootpath )
2039
- monkeypatch .chdir (rootpath )
2028
+ monkeypatch .setattr (pytester ._request .config ,"invocation_params" , Config .InvocationParams (
2029
+ args = (),
2030
+ plugins = (),
2031
+ dir = Path (rootpath ),
2032
+ ))
2040
2033
with mock .patch .object (hook , "fnpats" , ["*.py" ]):
2041
2034
assert hook .find_spec ("file" ) is None
2042
2035
@@ -2057,8 +2050,15 @@ def fix(): return 1
2057
2050
rootpath = f"{ os .getcwd ()} /tests"
2058
2051
if not os .path .exists (rootpath ):
2059
2052
mkdir (rootpath )
2060
- monkeypatch .chdir (rootpath )
2061
-
2053
+ monkeypatch .setattr (
2054
+ pytester ._request .config ,
2055
+ "invocation_params" ,
2056
+ Config .InvocationParams (
2057
+ args = (),
2058
+ plugins = (),
2059
+ dir = Path (rootpath ),
2060
+ )
2061
+ )
2062
2062
with mock .patch .object (hook , "fnpats" , ["*.py" ]):
2063
2063
assert hook .find_spec ("conftest" ) is not None
2064
2064
@@ -2082,7 +2082,15 @@ def test_assert_rewrite_correct_for_plugins(
2082
2082
rootpath = f"{ os .getcwd ()} /tests"
2083
2083
if not os .path .exists (rootpath ):
2084
2084
mkdir (rootpath )
2085
- monkeypatch .chdir (rootpath )
2085
+ monkeypatch .setattr (
2086
+ pytester ._request .config ,
2087
+ "invocation_params" ,
2088
+ Config .InvocationParams (
2089
+ args = (),
2090
+ plugins = (),
2091
+ dir = Path (rootpath ),
2092
+ )
2093
+ )
2086
2094
with mock .patch .object (hook , "fnpats" , ["*.py" ]):
2087
2095
assert hook .find_spec ("plugin" ) is not None
2088
2096
0 commit comments