TL;DR;
The
eval()method of the Frame object is not “inheriting” the__future__imports from the frame.Long explanation
Suppose I have a fixture in which I write my
assertstatements. If this fixture has strings on theassertstatement then when the assert fails I get the wrong kind of errors.The problem is that the pytest assertion rewrite mechanism is calling
eval()on the code that contains the frameTo better illustrate what happens, see this gist
The tests have the following output:
- test_plugin_fixture - fail
- test_conftest_fixture - fail
- test_inline_fixture - pass
- test_no_fixture - pass
The output of test_plugin_fixture (omitted some output for brevity):
$ pytest -k test_plugin_fixture msg = e.value.msg > assert msg.startswith('assert <classes.ValueAndString object'), msg E AssertionError: ValueError: ValueAndString(2, 'lkajflaskjfalskf') << Error!While debugging I found out that the
ValueAndStringconstructor was being called 3 times, instead of 2. The 3rd call happened incode.py:100, which is part of the py lib library. The “wrong” behaviour can be seen on the run_pyframe_eval.py.I’ve tested this code on Pytest 2.6.4 with Python 2.7.8 in Windows 7 - 64bits.
_______________________________________________
pytest-dev mailing list
pytest-dev@python.org
https://mail.python.org/mailman/listinfo/pytest-dev