[pytest-dev] Pytest fails with the wrong error when unicode_literals is present
nicoddemus at gmail.com
Tue Nov 25 13:49:44 CET 2014
Besides the problem that reinterpret is executing code in a context without
unicode_literals enabled, this also showcases that when moving a fixture
with has asserts on it from a test file to a conftest file, asserts will
not be rewritten anymore and reinterpretation will be used instead, which
might cause unexpected issues, as illustrated by Gustavo.
The first issue looks like a bug to me, not sure what to do about this
second point. Any thoughts?
On Mon, Nov 24, 2014 at 1:51 PM, Edison Gustavo Muenz <
edisongustavo at gmail.com> wrote:
> 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 assert statements. If this
> fixture has strings on the assert statement 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 frame
> To 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 ValueAndString constructor was being
> called 3 times, instead of 2. The 3rd call happened in code.py:100, which
> is part of the py lib <https://bitbucket.org/hpk42/py> 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 -
> pytest-dev mailing list
> pytest-dev at python.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the pytest-dev