coveragepy
coveragepy copied to clipboard
Intermittent failure in the CI due to set size changed while iterating
Started happening in the past two weeks, within the tox CI: https://github.com/tox-dev/tox/actions/runs/7499587729/job/20435785537 in .tox/py3.12/lib/python3.12/site-packages/coverage/collector.py:507: RuntimeError
_______________ ERROR at teardown of test_list_env_package_self ________________
self = <pytest_cov.plugin.TestContextPlugin object at 0x10d676150>
item = <Function test_list_env_package_self>
def pytest_runtest_teardown(self, item):
> self.switch_context(item, 'teardown')
item = <Function test_list_env_package_self>
self = <pytest_cov.plugin.TestContextPlugin object at 0x10d676150>
.tox/py3.12/lib/python3.12/site-packages/pytest_cov/plugin.py:382:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
.tox/py3.12/lib/python3.12/site-packages/pytest_cov/plugin.py:389: in switch_context
self.cov.switch_context(context)
context = 'tests/session/cmd/test_list_envs.py::test_list_env_package_self|teardown'
item = <Function test_list_env_package_self>
self = <pytest_cov.plugin.TestContextPlugin object at 0x10d676150>
when = 'teardown'
.tox/py3.12/lib/python3.12/site-packages/coverage/control.py:731: in switch_context
self._collector.switch_context(new_context)
new_context = 'tests/session/cmd/test_list_envs.py::test_list_env_package_self|teardown'
self = <coverage.control.Coverage object at 0x10c271820>
.tox/py3.12/lib/python3.12/site-packages/coverage/collector.py:439: in switch_context
self.flush_data()
new_context = 'tests/session/cmd/test_list_envs.py::test_list_env_package_self|teardown'
self = <Collector at 0x10ac527e0: CTracer>
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Collector at 0x10ac527e0: CTracer>
def flush_data(self) -> bool:
"""Save the collected data to our associated `CoverageData`.
Data may have also been saved along the way. This forces the
last of the data to be saved.
Returns True if there was data to save, False if not.
"""
if not self._activity():
return False
if self.branch:
if self.packed_arcs:
# Unpack the line number pairs packed into integers. See
# tracer.c:CTracer_record_pair for the C code that creates
# these packed ints.
arc_data: Dict[str, List[TArc]] = {}
packed_data = cast(Dict[str, Set[int]], self.data)
for fname, packeds in packed_data.items():
tuples = []
> for packed in packeds:
E RuntimeError: Set changed size during iteration
arc_data = {'/Users/runner/work/tox/tox/.tox/py3.12/lib/python3.12/site-packages/tox/__init__.py': [], '/Users/runner/work/tox/to...thon3.12/site-packages/tox/config/cli/env_var.py': [(43, -14), (-14, 22), (23, 43), (22, 23), (23, 24), (24, 23)], ...}
fname = '/Users/runner/work/tox/tox/.tox/py3.12/lib/python3.12/site-packages/tox/tox_env/python/virtual_env/package/pyproject.py'
l1 = 128
l2 = 124
packed = 130023552
packed_data = {'/Users/runner/work/tox/tox/.tox/py3.12/lib/python3.12/site-packages/tox/__init__.py': set(), '/Users/runner/work/tox.../site-packages/tox/config/cli/env_var.py': {24117270, 24117272, 25165847, 45088791, 1099534696462, 2199037935659}, ...}
packeds = {106954853, 108003430, 109052007, 110100584, 111149161, 112197738, ...}
self = <Collector at 0x10ac527e0: CTracer>
tuples = [(128, 124)]
.tox/py3.12/lib/python3.12/site-packages/coverage/collector.py:507: RuntimeError
Do you know what has changed in the last few weeks? Are you using a newer version of coverage? Is there a way for me to reproduce it?
I do not sadly, even in the CI happens semi-regularly. I don't have more than what I already put above.
@nedbat with the latest release, this now replicates reliably in Ubuntu see https://github.com/tox-dev/tox/actions/runs/7985950637/job/21805378783
This is fixed in commit 08fc997b6b3d881e8e5082b71ad6d6bcc4e2f752.
This is now released as part of coverage 7.4.3.