Skip to content

Commit 2aaea20

Browse files
committed
Use {node,config}.stash instead of ._store
Use the public name. The `_store` name is only because some plugins started using it anyway - will be removed at some point.
1 parent c6bdeb8 commit 2aaea20

File tree

11 files changed

+46
-46
lines changed

11 files changed

+46
-46
lines changed

src/_pytest/assertion/__init__.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,13 @@ def __init__(self, config: Config, mode) -> None:
8888

8989
def install_importhook(config: Config) -> rewrite.AssertionRewritingHook:
9090
"""Try to install the rewrite hook, raise SystemError if it fails."""
91-
config._store[assertstate_key] = AssertionState(config, "rewrite")
92-
config._store[assertstate_key].hook = hook = rewrite.AssertionRewritingHook(config)
91+
config.stash[assertstate_key] = AssertionState(config, "rewrite")
92+
config.stash[assertstate_key].hook = hook = rewrite.AssertionRewritingHook(config)
9393
sys.meta_path.insert(0, hook)
94-
config._store[assertstate_key].trace("installed rewrite import hook")
94+
config.stash[assertstate_key].trace("installed rewrite import hook")
9595

9696
def undo() -> None:
97-
hook = config._store[assertstate_key].hook
97+
hook = config.stash[assertstate_key].hook
9898
if hook is not None and hook in sys.meta_path:
9999
sys.meta_path.remove(hook)
100100

@@ -106,7 +106,7 @@ def pytest_collection(session: "Session") -> None:
106106
# This hook is only called when test modules are collected
107107
# so for example not in the managing process of pytest-xdist
108108
# (which does not collect test modules).
109-
assertstate = session.config._store.get(assertstate_key, None)
109+
assertstate = session.config.stash.get(assertstate_key, None)
110110
if assertstate:
111111
if assertstate.hook is not None:
112112
assertstate.hook.set_session(session)
@@ -169,7 +169,7 @@ def call_assertion_pass_hook(lineno: int, orig: str, expl: str) -> None:
169169

170170

171171
def pytest_sessionfinish(session: "Session") -> None:
172-
assertstate = session.config._store.get(assertstate_key, None)
172+
assertstate = session.config.stash.get(assertstate_key, None)
173173
if assertstate:
174174
if assertstate.hook is not None:
175175
assertstate.hook.set_session(None)

src/_pytest/assertion/rewrite.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def find_spec(
8787
) -> Optional[importlib.machinery.ModuleSpec]:
8888
if self._writing_pyc:
8989
return None
90-
state = self.config._store[assertstate_key]
90+
state = self.config.stash[assertstate_key]
9191
if self._early_rewrite_bailout(name, state):
9292
return None
9393
state.trace("find_module called for: %s" % name)
@@ -131,7 +131,7 @@ def exec_module(self, module: types.ModuleType) -> None:
131131
assert module.__spec__ is not None
132132
assert module.__spec__.origin is not None
133133
fn = Path(module.__spec__.origin)
134-
state = self.config._store[assertstate_key]
134+
state = self.config.stash[assertstate_key]
135135

136136
self._rewritten_names.add(module.__name__)
137137

src/_pytest/faulthandler.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,20 @@ def pytest_configure(config: Config) -> None:
2727
import faulthandler
2828

2929
stderr_fd_copy = os.dup(get_stderr_fileno())
30-
config._store[fault_handler_stderr_key] = open(stderr_fd_copy, "w")
31-
config._store[fault_handler_originally_enabled_key] = faulthandler.is_enabled()
32-
faulthandler.enable(file=config._store[fault_handler_stderr_key])
30+
config.stash[fault_handler_stderr_key] = open(stderr_fd_copy, "w")
31+
config.stash[fault_handler_originally_enabled_key] = faulthandler.is_enabled()
32+
faulthandler.enable(file=config.stash[fault_handler_stderr_key])
3333

3434

3535
def pytest_unconfigure(config: Config) -> None:
3636
import faulthandler
3737

3838
faulthandler.disable()
3939
# Close the dup file installed during pytest_configure.
40-
if fault_handler_stderr_key in config._store:
41-
config._store[fault_handler_stderr_key].close()
42-
del config._store[fault_handler_stderr_key]
43-
if config._store.get(fault_handler_originally_enabled_key, False):
40+
if fault_handler_stderr_key in config.stash:
41+
config.stash[fault_handler_stderr_key].close()
42+
del config.stash[fault_handler_stderr_key]
43+
if config.stash.get(fault_handler_originally_enabled_key, False):
4444
# Re-enable the faulthandler if it was originally enabled.
4545
faulthandler.enable(file=get_stderr_fileno())
4646

@@ -67,7 +67,7 @@ def get_timeout_config_value(config: Config) -> float:
6767
@pytest.hookimpl(hookwrapper=True, trylast=True)
6868
def pytest_runtest_protocol(item: Item) -> Generator[None, None, None]:
6969
timeout = get_timeout_config_value(item.config)
70-
stderr = item.config._store[fault_handler_stderr_key]
70+
stderr = item.config.stash[fault_handler_stderr_key]
7171
if timeout > 0 and stderr is not None:
7272
import faulthandler
7373

src/_pytest/fixtures.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ def add_funcarg_pseudo_fixture_def(
199199
name2pseudofixturedef = None
200200
else:
201201
default: Dict[str, FixtureDef[Any]] = {}
202-
name2pseudofixturedef = node._store.setdefault(
202+
name2pseudofixturedef = node.stash.setdefault(
203203
name2pseudofixturedef_key, default
204204
)
205205
if name2pseudofixturedef is not None and argname in name2pseudofixturedef:

src/_pytest/junitxml.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ def _warn_incompatibility_with_xunit2(
267267
"""Emit a PytestWarning about the given fixture being incompatible with newer xunit revisions."""
268268
from _pytest.warning_types import PytestWarning
269269

270-
xml = request.config._store.get(xml_key, None)
270+
xml = request.config.stash.get(xml_key, None)
271271
if xml is not None and xml.family not in ("xunit1", "legacy"):
272272
request.node.warn(
273273
PytestWarning(
@@ -322,7 +322,7 @@ def add_attr_noop(name: str, value: object) -> None:
322322

323323
attr_func = add_attr_noop
324324

325-
xml = request.config._store.get(xml_key, None)
325+
xml = request.config.stash.get(xml_key, None)
326326
if xml is not None:
327327
node_reporter = xml.node_reporter(request.node.nodeid)
328328
attr_func = node_reporter.add_attribute
@@ -370,7 +370,7 @@ def record_func(name: str, value: object) -> None:
370370
__tracebackhide__ = True
371371
_check_record_param_type("name", name)
372372

373-
xml = request.config._store.get(xml_key, None)
373+
xml = request.config.stash.get(xml_key, None)
374374
if xml is not None:
375375
record_func = xml.add_global_property # noqa
376376
return record_func
@@ -428,7 +428,7 @@ def pytest_configure(config: Config) -> None:
428428
# Prevent opening xmllog on worker nodes (xdist).
429429
if xmlpath and not hasattr(config, "workerinput"):
430430
junit_family = config.getini("junit_family")
431-
config._store[xml_key] = LogXML(
431+
config.stash[xml_key] = LogXML(
432432
xmlpath,
433433
config.option.junitprefix,
434434
config.getini("junit_suite_name"),
@@ -437,13 +437,13 @@ def pytest_configure(config: Config) -> None:
437437
junit_family,
438438
config.getini("junit_log_passing_tests"),
439439
)
440-
config.pluginmanager.register(config._store[xml_key])
440+
config.pluginmanager.register(config.stash[xml_key])
441441

442442

443443
def pytest_unconfigure(config: Config) -> None:
444-
xml = config._store.get(xml_key, None)
444+
xml = config.stash.get(xml_key, None)
445445
if xml:
446-
del config._store[xml_key]
446+
del config.stash[xml_key]
447447
config.pluginmanager.unregister(xml)
448448

449449

src/_pytest/logging.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ def handler(self) -> LogCaptureHandler:
372372
373373
:rtype: LogCaptureHandler
374374
"""
375-
return self._item._store[caplog_handler_key]
375+
return self._item.stash[caplog_handler_key]
376376

377377
def get_records(self, when: str) -> List[logging.LogRecord]:
378378
"""Get the logging records for one of the possible test phases.
@@ -385,7 +385,7 @@ def get_records(self, when: str) -> List[logging.LogRecord]:
385385
386386
.. versionadded:: 3.4
387387
"""
388-
return self._item._store[caplog_records_key].get(when, [])
388+
return self._item.stash[caplog_records_key].get(when, [])
389389

390390
@property
391391
def text(self) -> str:
@@ -694,8 +694,8 @@ def _runtest_for(self, item: nodes.Item, when: str) -> Generator[None, None, Non
694694
) as report_handler:
695695
caplog_handler.reset()
696696
report_handler.reset()
697-
item._store[caplog_records_key][when] = caplog_handler.records
698-
item._store[caplog_handler_key] = caplog_handler
697+
item.stash[caplog_records_key][when] = caplog_handler.records
698+
item.stash[caplog_handler_key] = caplog_handler
699699

700700
yield
701701

@@ -707,7 +707,7 @@ def pytest_runtest_setup(self, item: nodes.Item) -> Generator[None, None, None]:
707707
self.log_cli_handler.set_when("setup")
708708

709709
empty: Dict[str, List[logging.LogRecord]] = {}
710-
item._store[caplog_records_key] = empty
710+
item.stash[caplog_records_key] = empty
711711
yield from self._runtest_for(item, "setup")
712712

713713
@hookimpl(hookwrapper=True)
@@ -721,8 +721,8 @@ def pytest_runtest_teardown(self, item: nodes.Item) -> Generator[None, None, Non
721721
self.log_cli_handler.set_when("teardown")
722722

723723
yield from self._runtest_for(item, "teardown")
724-
del item._store[caplog_records_key]
725-
del item._store[caplog_handler_key]
724+
del item.stash[caplog_records_key]
725+
del item.stash[caplog_handler_key]
726726

727727
@hookimpl
728728
def pytest_runtest_logfinish(self) -> None:

src/_pytest/mark/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ def pytest_collection_modifyitems(items: "List[Item]", config: Config) -> None:
269269

270270

271271
def pytest_configure(config: Config) -> None:
272-
config._store[old_mark_config_key] = MARK_GEN._config
272+
config.stash[old_mark_config_key] = MARK_GEN._config
273273
MARK_GEN._config = config
274274

275275
empty_parameterset = config.getini(EMPTY_PARAMETERSET_OPTION)
@@ -282,4 +282,4 @@ def pytest_configure(config: Config) -> None:
282282

283283

284284
def pytest_unconfigure(config: Config) -> None:
285-
MARK_GEN._config = config._store.get(old_mark_config_key, None)
285+
MARK_GEN._config = config.stash.get(old_mark_config_key, None)

src/_pytest/pastebin.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,26 +37,26 @@ def pytest_configure(config: Config) -> None:
3737
# when using pytest-xdist, for example.
3838
if tr is not None:
3939
# pastebin file will be UTF-8 encoded binary file.
40-
config._store[pastebinfile_key] = tempfile.TemporaryFile("w+b")
40+
config.stash[pastebinfile_key] = tempfile.TemporaryFile("w+b")
4141
oldwrite = tr._tw.write
4242

4343
def tee_write(s, **kwargs):
4444
oldwrite(s, **kwargs)
4545
if isinstance(s, str):
4646
s = s.encode("utf-8")
47-
config._store[pastebinfile_key].write(s)
47+
config.stash[pastebinfile_key].write(s)
4848

4949
tr._tw.write = tee_write
5050

5151

5252
def pytest_unconfigure(config: Config) -> None:
53-
if pastebinfile_key in config._store:
54-
pastebinfile = config._store[pastebinfile_key]
53+
if pastebinfile_key in config.stash:
54+
pastebinfile = config.stash[pastebinfile_key]
5555
# Get terminal contents and delete file.
5656
pastebinfile.seek(0)
5757
sessionlog = pastebinfile.read()
5858
pastebinfile.close()
59-
del config._store[pastebinfile_key]
59+
del config.stash[pastebinfile_key]
6060
# Undo our patching in the terminal reporter.
6161
tr = config.pluginmanager.getplugin("terminalreporter")
6262
del tr._tw.__dict__["write"]

src/_pytest/skipping.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -237,33 +237,33 @@ def pytest_runtest_setup(item: Item) -> None:
237237
if skipped:
238238
raise skip.Exception(skipped.reason, _use_item_location=True)
239239

240-
item._store[xfailed_key] = xfailed = evaluate_xfail_marks(item)
240+
item.stash[xfailed_key] = xfailed = evaluate_xfail_marks(item)
241241
if xfailed and not item.config.option.runxfail and not xfailed.run:
242242
xfail("[NOTRUN] " + xfailed.reason)
243243

244244

245245
@hookimpl(hookwrapper=True)
246246
def pytest_runtest_call(item: Item) -> Generator[None, None, None]:
247-
xfailed = item._store.get(xfailed_key, None)
247+
xfailed = item.stash.get(xfailed_key, None)
248248
if xfailed is None:
249-
item._store[xfailed_key] = xfailed = evaluate_xfail_marks(item)
249+
item.stash[xfailed_key] = xfailed = evaluate_xfail_marks(item)
250250

251251
if xfailed and not item.config.option.runxfail and not xfailed.run:
252252
xfail("[NOTRUN] " + xfailed.reason)
253253

254254
yield
255255

256256
# The test run may have added an xfail mark dynamically.
257-
xfailed = item._store.get(xfailed_key, None)
257+
xfailed = item.stash.get(xfailed_key, None)
258258
if xfailed is None:
259-
item._store[xfailed_key] = xfailed = evaluate_xfail_marks(item)
259+
item.stash[xfailed_key] = xfailed = evaluate_xfail_marks(item)
260260

261261

262262
@hookimpl(hookwrapper=True)
263263
def pytest_runtest_makereport(item: Item, call: CallInfo[None]):
264264
outcome = yield
265265
rep = outcome.get_result()
266-
xfailed = item._store.get(xfailed_key, None)
266+
xfailed = item.stash.get(xfailed_key, None)
267267
if item.config.option.runxfail:
268268
pass # don't interfere
269269
elif call.excinfo and isinstance(call.excinfo.value, xfail.Exception):

testing/logging/test_fixture.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ def test_caplog_captures_for_all_stages(caplog, logging_during_setup_and_teardow
169169
assert [x.message for x in caplog.get_records("setup")] == ["a_setup_log"]
170170

171171
# This reaches into private API, don't use this type of thing in real tests!
172-
assert set(caplog._item._store[caplog_records_key]) == {"setup", "call"}
172+
assert set(caplog._item.stash[caplog_records_key]) == {"setup", "call"}
173173

174174

175175
def test_ini_controls_global_log_level(pytester: Pytester) -> None:

0 commit comments

Comments
 (0)