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
import _pytest ._code
@@ -1282,12 +1283,12 @@ def test_meta_path():
1282
1283
)
1283
1284
assert pytester .runpytest ().ret == 0
1284
1285
1285
-
1286
1286
def test_rootpath_base (self , pytester : Pytester , monkeypatch : MonkeyPatch ) -> None :
1287
1287
"""
1288
1288
Base cases for get rootpath from AssertionState
1289
1289
"""
1290
1290
from _pytest .assertion import AssertionState
1291
+
1291
1292
config = pytester .parseconfig ()
1292
1293
monkeypatch .chdir (pytester .path )
1293
1294
state = AssertionState (config , "rewrite" )
@@ -1299,23 +1300,26 @@ def test_rootpath_base(self, pytester: Pytester, monkeypatch: MonkeyPatch) -> No
1299
1300
state = AssertionState (config , "rewrite" )
1300
1301
assert state .rootpath == new_rootpath
1301
1302
1302
-
1303
1303
@pytest .mark .skipif (
1304
1304
sys .platform .startswith ("win32" ), reason = "cannot remove cwd on Windows"
1305
1305
)
1306
1306
@pytest .mark .skipif (
1307
1307
sys .platform .startswith ("sunos5" ), reason = "cannot remove cwd on Solaris"
1308
1308
)
1309
- def test_rootpath_cwd_removed (self , pytester : Pytester , monkeypatch : MonkeyPatch ) -> None :
1309
+ def test_rootpath_cwd_removed (
1310
+ self , pytester : Pytester , monkeypatch : MonkeyPatch
1311
+ ) -> None :
1310
1312
# Setup conditions for py's trying to os.getcwd() on py34
1311
1313
# when current working directory doesn't exist (previously triggered via xdist only).
1312
1314
# Ref: https://github.com/pytest-dev/py/pull/207
1313
1315
from _pytest .assertion import AssertionState
1316
+
1314
1317
config = pytester .parseconfig ()
1315
- monkeypatch .setattr (target = os , name = "getcwd" , value = Mock (side_effect = FileNotFoundError ))
1318
+ monkeypatch .setattr (
1319
+ target = os , name = "getcwd" , value = Mock (side_effect = FileNotFoundError )
1320
+ )
1316
1321
state = AssertionState (config , "rewrite" )
1317
- assert state .rootpath == os .path .abspath (os .sep )
1318
-
1322
+ assert state .rootpath == os .path .abspath (os .sep )
1319
1323
1320
1324
def test_write_pyc (self , pytester : Pytester , tmp_path ) -> None :
1321
1325
from _pytest .assertion import AssertionState
@@ -1920,6 +1924,7 @@ def hook(
1920
1924
if PathFinder.find_spec has been called.
1921
1925
"""
1922
1926
import importlib .machinery
1927
+
1923
1928
self .find_spec_calls : list [str ] = []
1924
1929
self .initial_paths : set [Path ] = set ()
1925
1930
@@ -1993,7 +1998,6 @@ def test_simple_failure():
1993
1998
assert hook .find_spec ("file" ) is not None
1994
1999
assert self .find_spec_calls == ["file" ]
1995
2000
1996
-
1997
2001
def test_assert_rewrites_only_rootpath (
1998
2002
self , pytester : Pytester , hook : AssertionRewritingHook , monkeypatch
1999
2003
) -> None :
@@ -2013,12 +2017,11 @@ def test_simple_failure():
2013
2017
2014
2018
rootpath = f"{ os .getcwd ()} /tests"
2015
2019
if not os .path .exists (rootpath ):
2016
- mkdir (rootpath )
2020
+ mkdir (rootpath )
2017
2021
monkeypatch .chdir (rootpath )
2018
2022
with mock .patch .object (hook , "fnpats" , ["*.py" ]):
2019
2023
assert hook .find_spec ("file" ) is None
2020
2024
2021
-
2022
2025
def test_assert_rewrite_correct_for_conftfest (
2023
2026
self , pytester : Pytester , hook : AssertionRewritingHook , monkeypatch
2024
2027
) -> None :
@@ -2035,12 +2038,11 @@ def fix(): return 1
2035
2038
2036
2039
rootpath = f"{ os .getcwd ()} /tests"
2037
2040
if not os .path .exists (rootpath ):
2038
- mkdir (rootpath )
2041
+ mkdir (rootpath )
2039
2042
monkeypatch .chdir (rootpath )
2040
2043
2041
2044
with mock .patch .object (hook , "fnpats" , ["*.py" ]):
2042
2045
assert hook .find_spec ("conftest" ) is not None
2043
-
2044
2046
2045
2047
def test_assert_rewrite_correct_for_plugins (
2046
2048
self , pytester : Pytester , hook : AssertionRewritingHook , monkeypatch
@@ -2061,12 +2063,11 @@ def test_assert_rewrite_correct_for_plugins(
2061
2063
hook .mark_rewrite ("plugin" )
2062
2064
rootpath = f"{ os .getcwd ()} /tests"
2063
2065
if not os .path .exists (rootpath ):
2064
- mkdir (rootpath )
2066
+ mkdir (rootpath )
2065
2067
monkeypatch .chdir (rootpath )
2066
2068
with mock .patch .object (hook , "fnpats" , ["*.py" ]):
2067
2069
assert hook .find_spec ("plugin" ) is not None
2068
2070
2069
-
2070
2071
@pytest .mark .skipif (
2071
2072
sys .platform .startswith ("win32" ), reason = "cannot remove cwd on Windows"
2072
2073
)
0 commit comments