Hi everyone, 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? Cheers, On Mon, Nov 24, 2014 at 1:51 PM, Edison Gustavo Muenz < edisongust...@gmail.com> wrote: > 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 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 > <https://gist.github.com/edisongustavo/5533a1c36de6cab6f39a> > > The tests > <https://gist.github.com/edisongustavo/5533a1c36de6cab6f39a#file-test_unicode_error_with_plugin_fixture-py> > 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 > <https://gist.github.com/edisongustavo/5533a1c36de6cab6f39a#file-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 > >
_______________________________________________ pytest-dev mailing list pytest-dev@python.org https://mail.python.org/mailman/listinfo/pytest-dev