pytest-dev / py

Python development support library (note: maintenance only)
MIT License
68 stars 106 forks source link

unittest.TestCase.assertWarns fails with py imported #110

Closed kernc closed 7 years ago

kernc commented 7 years ago

unittest.TestCase.assertWarns() fails with RuntimeError when py is imported.

This simple unit test:

import unittest
import warnings

import pandas as pd  # imports py.* somewhere deep

class Case(unittest.TestCase):
    def test_assertWarns(self):
        with self.assertWarns(UserWarning):
            warnings.warn('Some warning')

when run with:

python -m unittest example.py

fails with:

======================================================================
ERROR: test_assertWarns (example.Case)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/example.py", line 9, in test_assertWarns
    with self.assertWarns(UserWarning):
  File "/usr/lib/python3.4/unittest/case.py", line 205, in __enter__
    for v in sys.modules.values():
RuntimeError: dictionary changed size during iteration
----------------------------------------------------------------------

While I agree this is a unittest module issue (CPython bug 29620), I should hope it can be more quickly resolved on the pylib's side.

Ref: https://github.com/pytest-dev/pytest/issues/1288

kernc commented 7 years ago

Related CPython issue: https://bugs.python.org/issue29620

RonnyPfannschmidt commented 7 years ago

strictly speaking this is an apipkg bug