Skip to content

Using stdlib runpy.run_module() causes AttributeError: 'AssertionRewritingHook' object has no attribute 'get_code' #9007

@roo-oliv

Description

@roo-oliv

When using runpy's run_module function inside a pytest test and pointing to the very module of the test being run the execution will crash reporting AttributeError: 'AssertionRewritingHook' object has no attribute 'get_code'.

Minimum reproducible example:

# tests/dummy_test.py
import runpy


def test():
    runpy.run_module("tests.dummy_test")
# requirements.txt
pytest==6.2.4

System info:

  • OS: Ubuntu 20.04.2 LTS
  • Python Version: 3.8.10

Additional observations:

  • Calling an external function from other file in the test which calls runpy::run_module using the test's module as parameter will still yield the same error.
  • Calling runpy::run_module passing any module other than the test's very own module will yield no error.
  • Using runpy::run_path instead of run_module, passing the test's very own file path, will yield no error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: rewriterelated to the assertion rewrite mechanism

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions