Intermittent failure in the CI due to set size changed while iterating · Issue #1733 · nedbat/coveragepy (original) (raw)

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 =

def pytest_runtest_teardown(self, item):
  self.switch_context(item, 'teardown')

item = 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 = 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