How to get Pycharm's coverage tool to work with monkey patching?

def test_do_something():
    import custom_pandas_methods # patches collapse into pd.DataFrame
    df = pd.DataFrame({
        'a': [1,2,3],
        'b': [1,2,3],
    assert df.collapse('a') == 5

I'm running the above test in Pycharm using pytest (with the --cov option). It works fine when run without Pycharm's coverage tool.

However, when I "run with coverage", the test fails i.e.,

FPatching collapse into pandas.core.frame.DataFrame
E       RuntimeError: dictionary changed size during iteration

The RuntimeError occurs in, which contains the collapse method. Why would I get such an error?

1 comment
Comment actions Permalink

I asked this question on stackoverflow as well: 

Note that, on further review, monkey patching does NOT appear to be the issue.  I rewrote the test using a simple function and I get the same result i.e., Pycharm "test" works; Pycharm "test with coverage" fails.  I still struggling to see what could cause this.


Please sign in to leave a comment.