nedbat / coveragepy

The code coverage tool for Python
https://coverage.readthedocs.io
Apache License 2.0
2.97k stars 428 forks source link

Codecoverage assertion error on termination on child process. #1315

Closed JoanFM closed 2 years ago

JoanFM commented 2 years ago

Describe the bug During the pytest being run an exception from codecoverage is shown which I believe leads to hanging codecov resources.

I think this happens when we are sending a terminate signal from main process to a child process.

Traceback (most recent call last):
  File "/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/multiprocessing/util.py", line 300, in _run_finalizers
    finalizer()
  File "/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/multiprocessing/util.py", line 224, in __call__
    res = self._callback(*self._args, **self._kwargs)
  File "/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/pytest_cov/embed.py", line 99, in cleanup
    _cleanup(_active_cov)
  File "/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/pytest_cov/embed.py", line 84, in _cleanup
    cov.stop()
  File "/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/coverage/control.py", line 591, in stop
    self._collector.stop()
  File "/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/coverage/collector.py", line 353, in stop
    self.pause()
  File "/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/coverage/collector.py", line 375, in resume
    for tracer in self.tracers:
  File "/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/coverage/control.py", line 605, in _on_sigterm
    self._atexit("sigterm")
  File "/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/coverage/control.py", line 599, in _atexit
    self.stop()
  File "/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/coverage/control.py", line 591, in stop
    self._collector.stop()
  File "/opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/coverage/collector.py", line 350, in stop
    f"Expected current collector to be {self!r}, but it's {self._collectors[-1]!r}"
AssertionError: Expected current collector to be <Collector at 0x7f8854837c10: CTracer>, but it's <Collector at 0x7f8862cf6210: CTracer>
self._collectors:
  <Collector at 0x7f8862cf6210: CTracer>
                      <module> : /opt/hostedtoolcache/Python/3.7.12/x64/bin/pytest:8
                  console_main : /opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/_pytest/config/__init__.py:185
                          main : /opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/_pytest/config/__init__.py:143
                _prepareconfig : /opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/_pytest/config/__init__.py:319
                      __call__ : /opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/pluggy/_hooks.py:265
                     _hookexec : /opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/pluggy/_manager.py:80
                    _multicall : /opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/pluggy/_callers.py:39
          pytest_cmdline_parse : /opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/_pytest/config/__init__.py:1003
                         parse : /opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/_pytest/config/__init__.py:1283
                     _preparse : /opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/_pytest/config/__init__.py:1192
                      __call__ : /opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/pluggy/_hooks.py:265
                     _hookexec : /opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/pluggy/_manager.py:80
                    _multicall : /opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/pluggy/_callers.py:39
 pytest_load_initial_conftests : /opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/pytest_cov/plugin.py:149
                      __init__ : /opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/pytest_cov/plugin.py:200
                         start : /opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/pytest_cov/plugin.py:222
         ensure_topdir_wrapper : /opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/pytest_cov/engine.py:44
                         start : /opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/pytest_cov/engine.py:222
                         start : /opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/coverage/control.py:567
               _init_for_start : /opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/coverage/control.py:485
                      __init__ : /opt/hostedtoolcache/Python/3.7.12/x64/lib/python3.7/site-packages/coverage/collector.py:114
JoanFM commented 2 years ago

May it be related to #1310 ?

nedbat commented 2 years ago

Thanks for the report. Can you give me steps to reproduce the problem? Also, I'm curious how you got the compressed stack trace you show at the end?

nedbat commented 2 years ago

Hi, never mind about the stack trace, that's my own code doing that! :)

Can you try version 6.3.1 and see if it helps? If not, try to avoid using terminate, or, give me a way to try your code myself. Thanks.

JoanFM commented 2 years ago

Hello @nedbat,

I tried but not easy to get a reproducible step.

I will try 6.3.1 wheneve I have the time. Thank you very much for the prompt responses

nedbat commented 2 years ago

Feel free to re-open this if you get more information.