Skip to content

pickle.dump(self, f) - RuntimeError: dictionary changed size during iteration #14

@cle-b

Description

@cle-b

When using the httpdbg-allure option to save the headers and payload requests inside an Allure report, the following error can occur:

  /home/cle/dev/pytest-httpdbg/venv/lib/python3.12/site-packages/_pytest/threadexception.py:82: PytestUnhandledThreadExceptionWarning: Exception in thread Thread-1 (_save_to_disk_loop)
  
  Traceback (most recent call last):
    File "/usr/lib/python3.12/threading.py", line 1073, in _bootstrap_inner
      self.run()
    File "/usr/lib/python3.12/threading.py", line 1010, in run
      self._target(*self._args, **self._kwargs)
    File "/tmp/httpdbg_w2fuiz0b/sitecustomize.py", line 31, in _save_to_disk_loop
      self.records.save_to_disk(f"{self.fname}.httpdbgrecords")
    File "/home/cle/dev/httpdbg/httpdbg/records.py", line 487, in save_to_disk
      pickle.dump(self, f)
  RuntimeError: dictionary changed size during iteration
  
    warnings.warn(pytest.PytestUnhandledThreadExceptionWarning(msg))

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
======================= 60 passed, 3 warnings in 25.89s =======================

To reproduce it, create a file with the following test, and execute the following command: pytest demo/ --clean-alluredir --alluredir=/home/cle/dev/pytest-httpdbg/allure-results --httpdbg-allure -n 16 -v

import requests
import pytest

@pytest.mark.parametrize("id", range(60))
def test_one_request(httpbin, id):    
    for i in range(30):
        requests.get(f"{httpbin.url}/get?id={id}")

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions