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