Skip to content

Commit

Permalink
Define create_module()/exec_module() in AssertionRewritingHook to avo…
Browse files Browse the repository at this point in the history
…id ImportWarning

    __________ ERROR collecting testing/python/show_fixtures_per_test.py ___________
    /usr/lib/python3.10/site-packages/py/_path/local.py:704: in pyimport
        __import__(modname)
    <frozen importlib._bootstrap>:1026: in _find_and_load
        ???
    <frozen importlib._bootstrap>:1005: in _find_and_load_unlocked
        ???
    <frozen importlib._bootstrap>:681: in _load_unlocked
        ???
    E   ImportWarning: AssertionRewritingHook.exec_module() not found; falling back to load_module()
    !!!!!!!!!!!!!!!!!!! Interrupted: 59 errors during collection !!!!!!!!!!!!!!!!!!!
    =========================== 59 error in 3.65 seconds ===========================
  • Loading branch information
hroncok committed Jan 11, 2021
1 parent da7ca9e commit b446caf
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions changelog/8236.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Define ``create_module()`` and ``exec_module()`` methods in
``AssertionRewritingHook`` to get rid of ``ImportWarning`` on Python 3.10+.
6 changes: 6 additions & 0 deletions src/_pytest/assertion/rewrite.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,12 @@ def load_module(self, name):
raise
return sys.modules[name]

def create_module(self, spec):
return self.load_module(spec.name)

def exec_module(self, module):
pass

def is_package(self, name):
try:
fd, fn, desc = self._imp_find_module(name)
Expand Down

0 comments on commit b446caf

Please sign in to comment.