Skip to content

Commit 5fd182f

Browse files
committed
Use public API for adding config cleanup
No need to spuriously access the private internals of Config.
1 parent 61e506a commit 5fd182f

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed

src/_pytest/debugging.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def fin() -> None:
8888
pytestPDB._config,
8989
) = pytestPDB._saved.pop()
9090

91-
config._cleanup.append(fin)
91+
config.add_cleanup(fin)
9292

9393

9494
class pytestPDB:

src/_pytest/skipping.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def pytest_configure(config: Config) -> None:
4949
import pytest
5050

5151
old = pytest.xfail
52-
config._cleanup.append(lambda: setattr(pytest, "xfail", old))
52+
config.add_cleanup(lambda: setattr(pytest, "xfail", old))
5353

5454
def nop(*args, **kwargs):
5555
pass

src/_pytest/tmpdir.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -199,11 +199,11 @@ def pytest_configure(config: Config) -> None:
199199
to the tmp_path_factory session fixture.
200200
"""
201201
mp = MonkeyPatch()
202-
tmppath_handler = TempPathFactory.from_config(config, _ispytest=True)
203-
t = TempdirFactory(tmppath_handler, _ispytest=True)
204-
config._cleanup.append(mp.undo)
205-
mp.setattr(config, "_tmp_path_factory", tmppath_handler, raising=False)
206-
mp.setattr(config, "_tmpdirhandler", t, raising=False)
202+
config.add_cleanup(mp.undo)
203+
_tmp_path_factory = TempPathFactory.from_config(config, _ispytest=True)
204+
_tmpdirhandler = TempdirFactory(_tmp_path_factory, _ispytest=True)
205+
mp.setattr(config, "_tmp_path_factory", _tmp_path_factory, raising=False)
206+
mp.setattr(config, "_tmpdirhandler", _tmpdirhandler, raising=False)
207207

208208

209209
@fixture(scope="session")

testing/test_debugging.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -934,7 +934,7 @@ def test_sys_breakpointhook_configure_and_unconfigure(
934934
from _pytest.debugging import pytestPDB
935935
936936
def pytest_configure(config):
937-
config._cleanup.append(check_restored)
937+
config.add_cleanup(check_restored)
938938
939939
def check_restored():
940940
assert sys.breakpointhook == sys.__breakpointhook__
@@ -983,7 +983,7 @@ def test_environ_custom_class(
983983
os.environ['PYTHONBREAKPOINT'] = '_pytest._CustomDebugger.set_trace'
984984
985985
def pytest_configure(config):
986-
config._cleanup.append(check_restored)
986+
config.add_cleanup(check_restored)
987987
988988
def check_restored():
989989
assert sys.breakpointhook == sys.__breakpointhook__

0 commit comments

Comments
 (0)