Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running tests with coverage breaks on PyPy #7

Open
Sachaa-Thanasius opened this issue Oct 15, 2024 · 2 comments
Open

Running tests with coverage breaks on PyPy #7

Sachaa-Thanasius opened this issue Oct 15, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@Sachaa-Thanasius
Copy link
Owner

Sachaa-Thanasius commented Oct 15, 2024

Problem

Running with coverage via hatch test ... or coverage run -m pytest ... seems to break coverage, but only if run on pypy. The traceback indicates defer-imports's import hook machinery is leaking and polluting coverage's imports, but I'm not sure how or why. A cursory glance at the tests doesn't seem to indicate any leaking global state nor a reason for this to only happen on pypy.

Not sure when this started happening, but it was sometime before abccccc. I'll need to narrow that down.

Through print-debugging, it seems to happen within the super().exec_module() call in _DeferredSource.exec_module()?

Traceback

# Commands for reproducing (either should work):

# -- With hatch
hatch test tests/test_defer_imports.py::test_regular_import -i py=pypy3.9 --cover

# -- Without hatch, in a pypy3.9 venv
coverage run -m pytest tests/test_defer_imports.py::test_regular_import
When run with the hatch command above
============================================================== 1 passed in 0.14s =============================================================== 
────────────────────────────────────────────────────────────── hatch-test.pypy3.9 ───────────────────────────────────────────────────────────────
============================================================= test session starts ==============================================================
platform win32 -- Python 3.9.19[pypy-7.3.16-final], pytest-8.3.3, pluggy-1.5.0
rootdir: C:\Users\xxx\Projects\personal\defer-imports
configfile: pyproject.toml
plugins: mock-3.14.0, rerunfailures-14.0, xdist-3.6.1
collected 1 item

tests\test_defer_imports.py
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\_pytest\warnings.py", line 64, in catch_warnings_for_item
INTERNALERROR>     yield
INTERNALERROR>   File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\_pytest\warnings.py", line 112, in pytest_runtest_protocol
INTERNALERROR>     return (yield)
INTERNALERROR>   File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\pluggy\_callers.py", line 122, in _multicall
INTERNALERROR>     teardown.throw(exception)  # type: ignore[union-attr]
INTERNALERROR>   File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\_pytest\assertion\__init__.py", line 176, in pytest_runtest_protocol
INTERNALERROR>     return (yield)
INTERNALERROR>   File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\pluggy\_callers.py", line 122, in _multicall
INTERNALERROR>     teardown.throw(exception)  # type: ignore[union-attr]
INTERNALERROR>   File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\_pytest\unittest.py", line 429, in pytest_runtest_protocol
INTERNALERROR>     res = yield
INTERNALERROR>   File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\pluggy\_callers.py", line 122, in _multicall
INTERNALERROR>     teardown.throw(exception)  # type: ignore[union-attr]
INTERNALERROR>   File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\_pytest\faulthandler.py", line 88, in pytest_runtest_protocol
INTERNALERROR>     return (yield)
INTERNALERROR>   File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\pluggy\_callers.py", line 103, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\_pytest\runner.py", line 113, in pytest_runtest_protocol
INTERNALERROR>     runtestprotocol(item, nextitem=nextitem)
INTERNALERROR>   File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\_pytest\runner.py", line 132, in runtestprotocol
INTERNALERROR>     reports.append(call_and_report(item, "call", log))
INTERNALERROR>   File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\_pytest\runner.py", line 244, in call_and_report
INTERNALERROR>     report: TestReport = ihook.pytest_runtest_makereport(item=item, call=call)
INTERNALERROR>   File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\pluggy\_hooks.py", line 513, in __call__
INTERNALERROR>     return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
INTERNALERROR>   File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\pluggy\_manager.py", line 120, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR>   File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\pluggy\_callers.py", line 156, in _multicall
INTERNALERROR>     teardown[0].send(outcome)
INTERNALERROR>   File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\pytest_rerunfailures.py", line 505, in pytest_runtest_makereport
INTERNALERROR>     result = outcome.get_result()
INTERNALERROR>   File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\pluggy\_result.py", line 100, in get_result
INTERNALERROR>     raise exc.with_traceback(exc.__traceback__)
INTERNALERROR>   File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\pluggy\_callers.py", line 167, in _multicall
INTERNALERROR>     teardown.throw(outcome._exception)
INTERNALERROR>   File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\_pytest\skipping.py", line 269, in pytest_runtest_makereport
INTERNALERROR>     rep = yield
INTERNALERROR>   File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\pluggy\_callers.py", line 103, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\_pytest\runner.py", line 368, in pytest_runtest_makereport
INTERNALERROR>     return TestReport.from_item_and_call(item, call)
INTERNALERROR>   File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\_pytest\reports.py", line 376, in from_item_and_call
INTERNALERROR>     longrepr = item.repr_failure(excinfo)
INTERNALERROR>   File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\_pytest\python.py", line 1669, in repr_failure
INTERNALERROR>     return self._repr_failure_py(excinfo, style=style)
INTERNALERROR>   File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\_pytest\nodes.py", line 420, in _repr_failure_py
INTERNALERROR>     if isinstance(excinfo.value, FixtureLookupError):
INTERNALERROR> TypeError: isinstance() arg 2 must be a class, type, or tuple of classes and types, got _DeferredImportProxy
INTERNALERROR>
INTERNALERROR> During handling of the above exception, another exception occurred:
INTERNALERROR>
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\_pytest\main.py", line 283, in wrap_session
INTERNALERROR>     session.exitstatus = doit(config, session) or 0
INTERNALERROR>   File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\_pytest\main.py", line 337, in _main
INTERNALERROR>     config.hook.pytest_runtestloop(session=session)
INTERNALERROR>   File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\pluggy\_hooks.py", line 513, in __call__
INTERNALERROR>     return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
INTERNALERROR>   File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\pluggy\_manager.py", line 120, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR>   File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\pluggy\_callers.py", line 139, in _multicall
INTERNALERROR>     raise exception.with_traceback(exception.__traceback__)
INTERNALERROR>   File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\pluggy\_callers.py", line 122, in _multicall
INTERNALERROR>     teardown.throw(exception)  # type: ignore[union-attr]
INTERNALERROR>   File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\_pytest\logging.py", line 803, in pytest_runtestloop
INTERNALERROR>     return (yield)  # Run all the tests.
INTERNALERROR>   File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\pluggy\_callers.py", line 122, in _multicall
INTERNALERROR>     teardown.throw(exception)  # type: ignore[union-attr]
INTERNALERROR>   File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\_pytest\terminal.py", line 673, in pytest_runtestloop
INTERNALERROR>     result = yield
INTERNALERROR>   File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\pluggy\_callers.py", line 103, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\_pytest\main.py", line 362, in pytest_runtestloop
INTERNALERROR>     item.config.hook.pytest_runtest_protocol(item=item, nextitem=nextitem)
INTERNALERROR>   File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\pluggy\_hooks.py", line 513, in __call__
INTERNALERROR>     return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
INTERNALERROR>   File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\pluggy\_manager.py", line 120, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR>   File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\pluggy\_callers.py", line 139, in _multicall
INTERNALERROR>     raise exception.with_traceback(exception.__traceback__)
INTERNALERROR>   File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\pluggy\_callers.py", line 122, in _multicall
INTERNALERROR>     teardown.throw(exception)  # type: ignore[union-attr]
INTERNALERROR>   File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\_pytest\warnings.py", line 112, in pytest_runtest_protocol
INTERNALERROR>     return (yield)
INTERNALERROR>   File "C:\Users\xxx\AppData\Local\Programs\Python\pypy3.9\Lib\contextlib.py", line 137, in __exit__
INTERNALERROR>     self.gen.throw(typ, value, traceback)
INTERNALERROR>   File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\_pytest\warnings.py", line 67, in catch_warnings_for_item
INTERNALERROR>     ihook.pytest_warning_recorded.call_historic(
INTERNALERROR>   File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\pluggy\_hooks.py", line 535, in call_historic
INTERNALERROR>     res = self._hookexec(self.name, self._hookimpls.copy(), kwargs, False)
INTERNALERROR>   File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\pluggy\_manager.py", line 120, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR>   File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\pluggy\_callers.py", line 139, in _multicall
INTERNALERROR>     raise exception.with_traceback(exception.__traceback__)
INTERNALERROR>   File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\pluggy\_callers.py", line 103, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\_pytest\terminal.py", line 558, in pytest_warning_recorded
INTERNALERROR>     message = warning_record_to_str(warning_message)
INTERNALERROR> TypeError: '_DeferredImportProxy' object is not callable
Traceback (most recent call last):
  File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\_pytest\config\__init__.py", line 175, in main
    ret: ExitCode | int = config.hook.pytest_cmdline_main(config=config)
  File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\pluggy\_hooks.py", line 513, in __call__
    return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
  File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\pluggy\_manager.py", line 120, in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
  File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\pluggy\_callers.py", line 139, in _multicall
    raise exception.with_traceback(exception.__traceback__)
  File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\pluggy\_callers.py", line 103, in _multicall
    res = hook_impl.function(*args)
  File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\_pytest\main.py", line 330, in pytest_cmdline_main
    return wrap_session(config, _main)
  File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\_pytest\main.py", line 318, in wrap_session
    config.hook.pytest_sessionfinish(
  File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\pluggy\_hooks.py", line 513, in __call__
    return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
  File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\pluggy\_manager.py", line 120, in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
  File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\pluggy\_callers.py", line 139, in _multicall
    raise exception.with_traceback(exception.__traceback__)
  File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\pluggy\_callers.py", line 122, in _multicall
    teardown.throw(exception)  # type: ignore[union-attr]
  File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\_pytest\logging.py", line 868, in pytest_sessionfinish
    return (yield)
  File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\pluggy\_callers.py", line 122, in _multicall
    teardown.throw(exception)  # type: ignore[union-attr]
  File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\_pytest\terminal.py", line 893, in pytest_sessionfinish
    result = yield
  File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\pluggy\_callers.py", line 122, in _multicall
    teardown.throw(exception)  # type: ignore[union-attr]
  File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\_pytest\warnings.py", line 141, in pytest_sessionfinish
    return (yield)
  File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\pluggy\_callers.py", line 103, in _multicall
    res = hook_impl.function(*args)
  File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\_pytest\runner.py", line 107, in pytest_sessionfinish
    session._setupstate.teardown_exact(None)
  File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\_pytest\runner.py", line 557, in teardown_exact
    raise exceptions[0]
  File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\_pytest\runner.py", line 546, in teardown_exact
    fin()
  File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\_pytest\fixtures.py", line 1024, in finish
    node = request.node
  File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\_pytest\fixtures.py", line 748, in node
    node = get_scope_node(self._pyfuncitem, scope)
  File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\_pytest\fixtures.py", line 138, in get_scope_node
    import _pytest.python
  File "C:\Users\xxx\Projects\personal\defer-imports\src\defer_imports\__init__.py", line 1184, in _deferred___import__
    base_parent = parent = locals[name_parts[0]]
TypeError: 'NoneType' object is not subscriptable (key '_pytest')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\pytest\__main__.py", line 9, in <module>
    raise SystemExit(pytest.console_main())
  File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\_pytest\config\__init__.py", line 201, in console_main
    code = main()
  File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\_pytest\config\__init__.py", line 181, in main
    config._ensure_unconfigure()
  File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\_pytest\config\__init__.py", line 1123, in _ensure_unconfigure
    self.hook.pytest_unconfigure(config=self)
  File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\pluggy\_hooks.py", line 513, in __call__
    return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
  File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\pluggy\_manager.py", line 120, in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
  File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\pluggy\_callers.py", line 139, in _multicall
    raise exception.with_traceback(exception.__traceback__)
  File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\pluggy\_callers.py", line 103, in _multicall
    res = hook_impl.function(*args)
  File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\_pytest\faulthandler.py", line 44, in pytest_unconfigure
    faulthandler.disable()
  File "C:\Users\xxx\Projects\personal\defer-imports\src\defer_imports\__init__.py", line 1080, in __getattr__
    raise AttributeError(msg)
AttributeError: proxy for module 'faulthandler' has no attribute 'disable'
C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\coverage\pytracer.py:346: CoverageWarning: Trace function changed, data is likely wrong: None != <bound method PyTracer._trace of <PyTracer at 0x2a0aec72b80: 565 data points in 3 files>> (trace-changed)
Traceback (most recent call last):
  File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\_pytest\config\__init__.py", line 175, in main
    ret: ExitCode | int = config.hook.pytest_cmdline_main(config=config)
  File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\pluggy\_hooks.py", line 513, in __call__
    return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
  File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\pluggy\_manager.py", line 120, in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
  File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\pluggy\_callers.py", line 139, in _multicall
    raise exception.with_traceback(exception.__traceback__)
  File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\pluggy\_callers.py", line 103, in _multicall
    res = hook_impl.function(*args)
  File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\_pytest\main.py", line 330, in pytest_cmdline_main
    return wrap_session(config, _main)
  File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\_pytest\main.py", line 318, in wrap_session
    config.hook.pytest_sessionfinish(
  File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\pluggy\_hooks.py", line 513, in __call__
    return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
  File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\pluggy\_manager.py", line 120, in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
  File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\pluggy\_callers.py", line 139, in _multicall
    raise exception.with_traceback(exception.__traceback__)
  File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\pluggy\_callers.py", line 122, in _multicall
    teardown.throw(exception)  # type: ignore[union-attr]
  File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\_pytest\logging.py", line 868, in pytest_sessionfinish
    return (yield)
  File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\pluggy\_callers.py", line 122, in _multicall
    teardown.throw(exception)  # type: ignore[union-attr]
  File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\_pytest\terminal.py", line 893, in pytest_sessionfinish
    result = yield
  File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\pluggy\_callers.py", line 122, in _multicall
    teardown.throw(exception)  # type: ignore[union-attr]
  File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\_pytest\warnings.py", line 141, in pytest_sessionfinish
    return (yield)
  File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\pluggy\_callers.py", line 103, in _multicall
    res = hook_impl.function(*args)
  File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\_pytest\runner.py", line 107, in pytest_sessionfinish
    session._setupstate.teardown_exact(None)
  File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\_pytest\runner.py", line 557, in teardown_exact
    raise exceptions[0]
  File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\_pytest\runner.py", line 546, in teardown_exact
    fin()
  File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\_pytest\fixtures.py", line 1024, in finish
    node = request.node
  File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\_pytest\fixtures.py", line 748, in node
    node = get_scope_node(self._pyfuncitem, scope)
  File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\_pytest\fixtures.py", line 138, in get_scope_node
    import _pytest.python
  File "C:\Users\xxx\Projects\personal\defer-imports\src\defer_imports\__init__.py", line 1184, in _deferred___import__
    base_parent = parent = locals[name_parts[0]]
TypeError: 'NoneType' object is not subscriptable (key '_pytest')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\coverage\execfile.py", line 208, in run
    exec(code, main_mod.__dict__)
  File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\pytest\__main__.py", line 9, in <module>
    raise SystemExit(pytest.console_main())
  File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\_pytest\config\__init__.py", line 201, in console_main
    code = main()
  File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\_pytest\config\__init__.py", line 181, in main
    config._ensure_unconfigure()
  File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\_pytest\config\__init__.py", line 1123, in _ensure_unconfigure
    self.hook.pytest_unconfigure(config=self)
  File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\pluggy\_hooks.py", line 513, in __call__
    return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
  File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\pluggy\_manager.py", line 120, in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
  File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\pluggy\_callers.py", line 139, in _multicall
    raise exception.with_traceback(exception.__traceback__)
  File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\pluggy\_callers.py", line 103, in _multicall
    res = hook_impl.function(*args)
  File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\_pytest\faulthandler.py", line 44, in pytest_unconfigure
    faulthandler.disable()
  File "C:\Users\xxx\Projects\personal\defer-imports\src\defer_imports\__init__.py", line 1080, in __getattr__
    raise AttributeError(msg)
AttributeError: proxy for module 'faulthandler' has no attribute 'disable'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\coverage\cmdline.py", line 858, in do_run
    runner.run()
  File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\coverage\execfile.py", line 252, in run
    sys.exit(1)
SystemExit: 1

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\xxx\AppData\Local\Programs\Python\pypy3.9\Lib\runpy.py", line 200, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Users\xxx\AppData\Local\Programs\Python\pypy3.9\Lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\Scripts\coverage.exe\__main__.py", line 8, in <module>
    sys.exit(main())
  File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\coverage\cmdline.py", line 970, in main
    status = CoverageScript().command_line(argv)
  File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\coverage\cmdline.py", line 681, in command_line
    return self.do_run(options, args)
  File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\coverage\cmdline.py", line 865, in do_run
    self.coverage.save()
  File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\coverage\control.py", line 789, in save
    data = self.get_data()
  File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\coverage\control.py", line 869  File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\coverage\cmdline.py", line 865, in do_run
    self.coverage.save()
  File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\coverage\control.py", line 789, in save
    data = self.get_data()
  File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\coverage\cmdline.py", line 865, in do_run
    self.coverage.save()
  File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\coverage\control.py", line 789, in save
  File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\coverage\cmdline.py", line 865, in do_run
    self.coverage.save()
  File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\coverage\control.py", line 789  File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\coverage\cmdline.py", line 865, in do_run
    self.coverage.save()
  File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\coverage\control.py", line 789  File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\coverage\cmdline.py", line 865, in do_run
    self.coverage.save()
  File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\coverage\cmdline.py", line 865, in do_run
, in do_run
    self.coverage.save()
    self.coverage.save()
  File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\coverage\control.py", line 789, in save
    data = self.get_data()
  File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\coverage\control.py", line 869, in get_data
    if self._collector.flush_data():
  File "C:\Users\xxx\AppData\Local\hatch\env\virtual\defer-imports\tJ7r-Y5k\hatch-test.pypy3.9\lib\site-packages\coverage\collector.py", line 484, in flush_data
    arc_data = cast(dict[str, list[TArc]], self.data)
TypeError: _deferred___import__() missing 2 required positional arguments: 'globals' and 'locals'
@Sachaa-Thanasius Sachaa-Thanasius added the bug Something isn't working label Oct 15, 2024
@Sachaa-Thanasius Sachaa-Thanasius changed the title Determine why running with coverage breaks on pypy Determine why running tests with coverage breaks on PyPy Oct 15, 2024
@Sachaa-Thanasius Sachaa-Thanasius changed the title Determine why running tests with coverage breaks on PyPy Running tests with coverage breaks on PyPy Oct 15, 2024
@Sachaa-Thanasius
Copy link
Owner Author

Sachaa-Thanasius commented Oct 15, 2024

It's an issue with coverage: 7.6.1 works fine, but the versions afterwards (currently the max version is 7.6.3) hit this.

@Sachaa-Thanasius
Copy link
Owner Author

Sachaa-Thanasius commented Oct 15, 2024

Using git bisect, I managed to track down the bad commit to . . . one that's only an automatic refactor via pyupgrade? 84b7f3de20103d6c26524aaaea661af660c859e0

Commands for Reproduction

# Clone the necessary repos.
git clone git@github.com:nedbat/coveragepy
cd coveragepy
git clone git@github.com:Sachaa-Thanasius/defer-imports

# Create a pypy env and activate it.
pypy3.9 -m venv .venv
.venv/Scripts/activate

# Prepare environment.
python -m pip install pytest

# Start bisecting.
git bisect start
git bisect bad 7.6.1
git bisect good 7.6.2
git bisect run bash -c "coverage run -m pytest defer-imports/tests"

Output

84b7f3de20103d6c26524aaaea661af660c859e0 is the first bad commit
commit 84b7f3de20103d6c26524aaaea661af660c859e0 (HEAD)
Author: Ned Batchelder <[email protected]>
Date:   Tue Sep 24 07:42:27 2024 -0400

    refactor: pyupgrade --py39-plus coverage/*.py tests/*.py

 coverage/annotate.py       |  3 ++-
 coverage/bytecode.py       |  2 +-
 coverage/collector.py      | 11 ++++++-----
 coverage/config.py         |  3 ++-
 coverage/context.py        |  3 ++-
 coverage/control.py        |  5 +++--
 coverage/data.py           |  5 +++--
 coverage/debug.py          |  3 ++-
 coverage/env.py            |  3 ++-
 coverage/files.py          |  3 ++-
 coverage/html.py           |  5 +++--
 coverage/inorout.py        |  3 ++-
 coverage/jsonreport.py     |  5 +++--
 coverage/lcovreport.py     |  3 ++-
 coverage/misc.py           |  5 +++--
 coverage/numbits.py        |  2 +-
 coverage/parser.py         |  9 +++++----
 coverage/phystokens.py     |  2 +-
 coverage/plugin.py         |  3 ++-
 coverage/plugin_support.py |  3 ++-
 coverage/python.py         |  3 ++-
 coverage/pytracer.py       |  6 +++---
 coverage/report.py         |  3 ++-
 coverage/report_core.py    |  3 ++-
 coverage/results.py        |  3 ++-
 coverage/sqldata.py        |  4 ++--
 coverage/sqlitedb.py       |  5 +++--
 coverage/sysmon.py         |  8 ++++----
 coverage/templite.py       |  2 +-
 coverage/tomlconfig.py     |  3 ++-
 coverage/types.py          | 15 ++++++++-------
 coverage/xmlreport.py      |  3 ++-
 tests/conftest.py          |  2 +-
 tests/coveragetest.py      |  3 ++-
 tests/goldtest.py          |  2 +-
 tests/helpers.py           |  3 ++-
 tests/mixins.py            |  5 +++--
 tests/plugin_config.py     |  2 +-
 tests/test_api.py          |  3 ++-
 tests/test_cmdline.py      |  3 ++-
 tests/test_concurrency.py  |  2 +-
 tests/test_data.py         |  3 ++-
 tests/test_debug.py        |  3 ++-
 tests/test_execfile.py     |  3 ++-
 tests/test_files.py        |  3 ++-
 tests/test_numbits.py      |  2 +-
 tests/test_report_core.py  |  3 ++-
 tests/test_results.py      |  3 ++-
 tests/test_setup.py        |  2 +-
 tests/test_venv.py         |  3 ++-
 tests/test_xml.py          |  3 ++-
 51 files changed, 115 insertions(+), 77 deletions(-)
 bisect found first bad commit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant