7
7
from _pytest .assertion import rewrite
8
8
from _pytest .assertion import truncate
9
9
from _pytest .assertion import util
10
+ from _pytest .assertion .rewrite import assertstate_key
10
11
from _pytest .compat import TYPE_CHECKING
11
12
from _pytest .config import hookimpl
12
13
@@ -82,13 +83,13 @@ def __init__(self, config, mode):
82
83
83
84
def install_importhook (config ):
84
85
"""Try to install the rewrite hook, raise SystemError if it fails."""
85
- config ._assertstate = AssertionState (config , "rewrite" )
86
- config ._assertstate .hook = hook = rewrite .AssertionRewritingHook (config )
86
+ config ._store [ assertstate_key ] = AssertionState (config , "rewrite" )
87
+ config ._store [ assertstate_key ] .hook = hook = rewrite .AssertionRewritingHook (config )
87
88
sys .meta_path .insert (0 , hook )
88
- config ._assertstate .trace ("installed rewrite import hook" )
89
+ config ._store [ assertstate_key ] .trace ("installed rewrite import hook" )
89
90
90
91
def undo ():
91
- hook = config ._assertstate .hook
92
+ hook = config ._store [ assertstate_key ] .hook
92
93
if hook is not None and hook in sys .meta_path :
93
94
sys .meta_path .remove (hook )
94
95
@@ -100,7 +101,7 @@ def pytest_collection(session: "Session") -> None:
100
101
# this hook is only called when test modules are collected
101
102
# so for example not in the master process of pytest-xdist
102
103
# (which does not collect test modules)
103
- assertstate = getattr ( session .config , "_assertstate" , None )
104
+ assertstate = session .config . _store . get ( assertstate_key , None )
104
105
if assertstate :
105
106
if assertstate .hook is not None :
106
107
assertstate .hook .set_session (session )
@@ -163,7 +164,7 @@ def call_assertion_pass_hook(lineno, orig, expl):
163
164
164
165
165
166
def pytest_sessionfinish (session ):
166
- assertstate = getattr ( session .config , "_assertstate" , None )
167
+ assertstate = session .config . _store . get ( assertstate_key , None )
167
168
if assertstate :
168
169
if assertstate .hook is not None :
169
170
assertstate .hook .set_session (None )
0 commit comments