You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I had one test that needed the functionality of another, i.e. the first modifies the server-state in a way that the second test also needs. The pattern is probably not recommended, but we did this:
The first test: test_b.py
importpytestfromtornado.genimportsleep@pytest.mark.gen_testdeftest_b():
yieldsleep(0.1) # the real case actually did something
This passes.
The second test: test_c.py
importpytestfrom .test_bimporttest_b@pytest.mark.gen_testdeftest_c():
yieldtest_b()
# [...] and something else
This also passes.
BUT! only if called test_c.py - if you rename the SAME test to test_a.py (or whatever gets sorted before test_b, it fails with:
I don't know if this can really be "fixed" - in the end our pattern of "called the test function" is probably not recommended, and it's trivial to work around by putting the shared code in it's own coroutine.
However, since we spent hours debugging this, it's maybe worth mentioning for others?
The text was updated successfully, but these errors were encountered:
I came across something weird with python3
I had one test that needed the functionality of another, i.e. the first modifies the server-state in a way that the second test also needs. The pattern is probably not recommended, but we did this:
The first test: test_b.py
This passes.
The second test: test_c.py
This also passes.
BUT! only if called
test_c.py
- if you rename the SAME test totest_a.py
(or whatever gets sorted beforetest_b
, it fails with:Tornado doesn't think the function is a coroutine, because the
CO_ITERABLE_COROUTINE
flag is not set on the code.This happens because the tests are run in alphabetical order, and if the
test_b
is run by itself once before this library callstornado.gen.pytest
on it: https://github.com/eugeniy/pytest-tornado/blob/master/pytest_tornado/plugin.py#L106which in turn calls
types.coroutine
, which modifies the functions code object in place to set the flag: https://github.com/python/cpython/blob/master/Lib/types.py#L228-L241I don't know if this can really be "fixed" - in the end our pattern of "called the test function" is probably not recommended, and it's trivial to work around by putting the shared code in it's own coroutine.
However, since we spent hours debugging this, it's maybe worth mentioning for others?
The text was updated successfully, but these errors were encountered: