22
22
from typing import cast
23
23
from unittest import mock
24
24
import zipfile
25
+
25
26
from mock .mock import Mock
26
27
27
28
from _pytest .monkeypatch import MonkeyPatch
@@ -1300,12 +1301,12 @@ def test_meta_path():
1300
1301
)
1301
1302
assert pytester .runpytest ().ret == 0
1302
1303
1303
-
1304
1304
def test_rootpath_base (self , pytester : Pytester , monkeypatch : MonkeyPatch ) -> None :
1305
1305
"""
1306
1306
Base cases for get rootpath from AssertionState
1307
1307
"""
1308
1308
from _pytest .assertion import AssertionState
1309
+
1309
1310
config = pytester .parseconfig ()
1310
1311
monkeypatch .chdir (pytester .path )
1311
1312
state = AssertionState (config , "rewrite" )
@@ -1317,23 +1318,26 @@ def test_rootpath_base(self, pytester: Pytester, monkeypatch: MonkeyPatch) -> No
1317
1318
state = AssertionState (config , "rewrite" )
1318
1319
assert state .rootpath == new_rootpath
1319
1320
1320
-
1321
1321
@pytest .mark .skipif (
1322
1322
sys .platform .startswith ("win32" ), reason = "cannot remove cwd on Windows"
1323
1323
)
1324
1324
@pytest .mark .skipif (
1325
1325
sys .platform .startswith ("sunos5" ), reason = "cannot remove cwd on Solaris"
1326
1326
)
1327
- def test_rootpath_cwd_removed (self , pytester : Pytester , monkeypatch : MonkeyPatch ) -> None :
1327
+ def test_rootpath_cwd_removed (
1328
+ self , pytester : Pytester , monkeypatch : MonkeyPatch
1329
+ ) -> None :
1328
1330
# Setup conditions for py's trying to os.getcwd() on py34
1329
1331
# when current working directory doesn't exist (previously triggered via xdist only).
1330
1332
# Ref: https://github.com/pytest-dev/py/pull/207
1331
1333
from _pytest .assertion import AssertionState
1334
+
1332
1335
config = pytester .parseconfig ()
1333
- monkeypatch .setattr (target = os , name = "getcwd" , value = Mock (side_effect = FileNotFoundError ))
1336
+ monkeypatch .setattr (
1337
+ target = os , name = "getcwd" , value = Mock (side_effect = FileNotFoundError )
1338
+ )
1334
1339
state = AssertionState (config , "rewrite" )
1335
- assert state .rootpath == os .path .abspath (os .sep )
1336
-
1340
+ assert state .rootpath == os .path .abspath (os .sep )
1337
1341
1338
1342
def test_write_pyc (self , pytester : Pytester , tmp_path ) -> None :
1339
1343
from _pytest .assertion import AssertionState
@@ -1938,6 +1942,7 @@ def hook(
1938
1942
if PathFinder.find_spec has been called.
1939
1943
"""
1940
1944
import importlib .machinery
1945
+
1941
1946
self .find_spec_calls : list [str ] = []
1942
1947
self .initial_paths : set [Path ] = set ()
1943
1948
@@ -2011,7 +2016,6 @@ def test_simple_failure():
2011
2016
assert hook .find_spec ("file" ) is not None
2012
2017
assert self .find_spec_calls == ["file" ]
2013
2018
2014
-
2015
2019
def test_assert_rewrites_only_rootpath (
2016
2020
self , pytester : Pytester , hook : AssertionRewritingHook , monkeypatch
2017
2021
) -> None :
@@ -2031,12 +2035,11 @@ def test_simple_failure():
2031
2035
2032
2036
rootpath = f"{ os .getcwd ()} /tests"
2033
2037
if not os .path .exists (rootpath ):
2034
- mkdir (rootpath )
2038
+ mkdir (rootpath )
2035
2039
monkeypatch .chdir (rootpath )
2036
2040
with mock .patch .object (hook , "fnpats" , ["*.py" ]):
2037
2041
assert hook .find_spec ("file" ) is None
2038
2042
2039
-
2040
2043
def test_assert_rewrite_correct_for_conftfest (
2041
2044
self , pytester : Pytester , hook : AssertionRewritingHook , monkeypatch
2042
2045
) -> None :
@@ -2053,12 +2056,11 @@ def fix(): return 1
2053
2056
2054
2057
rootpath = f"{ os .getcwd ()} /tests"
2055
2058
if not os .path .exists (rootpath ):
2056
- mkdir (rootpath )
2059
+ mkdir (rootpath )
2057
2060
monkeypatch .chdir (rootpath )
2058
2061
2059
2062
with mock .patch .object (hook , "fnpats" , ["*.py" ]):
2060
2063
assert hook .find_spec ("conftest" ) is not None
2061
-
2062
2064
2063
2065
def test_assert_rewrite_correct_for_plugins (
2064
2066
self , pytester : Pytester , hook : AssertionRewritingHook , monkeypatch
@@ -2079,12 +2081,11 @@ def test_assert_rewrite_correct_for_plugins(
2079
2081
hook .mark_rewrite ("plugin" )
2080
2082
rootpath = f"{ os .getcwd ()} /tests"
2081
2083
if not os .path .exists (rootpath ):
2082
- mkdir (rootpath )
2084
+ mkdir (rootpath )
2083
2085
monkeypatch .chdir (rootpath )
2084
2086
with mock .patch .object (hook , "fnpats" , ["*.py" ]):
2085
2087
assert hook .find_spec ("plugin" ) is not None
2086
2088
2087
-
2088
2089
@pytest .mark .skipif (
2089
2090
sys .platform .startswith ("win32" ), reason = "cannot remove cwd on Windows"
2090
2091
)
0 commit comments