Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Python3: problem with new_instances isolation #13
I am porting our code from python2.7 to python3.4 and tests started failing due to missing isolation in tests where
I thought if it's an obvious bug it's easy to reproduce so I created a minimal testcase I would expect to reproduce it, but sadly it doesn't. I add it here anyway, because it illustrates the problem.
I would expect test_check_isolation to fail because the new_instances mock is wrongly still active from the other test, but this works with no problem on python2 and python3.
A workaround in the production code is two separate the two classes that affect each others test behaviour into two different modules.
I would like to understand why this is happening and what else could cause this behaviour. Any ideas?
I don't have any immediate advice, but there are some things to consider that might help while trying to reproduce this:
Maybe answers to these questions can help us get a reproducer or at least an idea what might be causing the problem.
I worked through your list and the last one lead me to a minimal test case (only on file necessary and supersimple), which I could swear I tried already before. Maybe I am halluzinating as well, because the day was very long ... anyway here it is. It passes on 2.7.6 and fails on 3.4.3 and 3.5.0.
This is the Error:
I believe we're hitting a bug in Python 3 itself . The minimal reproducer actually doesn't need flexmock at all:
It seems that there's nothing I can do about this until this is fixed in Python. I'll leave this issue opened for now and I'll keep an eye on that Python issue to see where this will go.
added a commit
Jan 20, 2016
referenced this issue
Oct 19, 2016
http_error = HTTPError('broken for testing') broken_http_client = flexmock(HTTPClient('example.com')) broken_http_client.should_receive('request').and_raise(http_error) flexmock(HTTPClient).new_instances(broken_http_client)
The test that does this stubbing works correctly, but once I added this tests, other tests that result in the HTTPClient constructor being called broke down with the following error:
flexmock.MethodSignatureError: __new__(<class 'lib.http.HTTPSClient'>, "pg.eet.cz", proxy=None, logger=<eet.loggers.EETLogger object at 0x7f973674d9e8>, verify=True)
The method signature is correct as verified by both the tests passing before adding this one and the program communicating correctly over the network. But even if the method signature was wrong, this test shouldn't affect the other ones. I also tried to move the test into it's own class in a separate file (package), but nothing changed.
P.S. I'm using python version 3.5.2