Closed pytestbot closed 9 years ago
Original comment by Roman Levin (BitBucket: romanlevin, GitHub: romanlevin):
Seems to be caused by test failure passing the partial
to py.code.Code
, which expects its input to be a code
object or have a code
object in its __code__
attribute.
partial
s don't have a code
object, hence the error.
test_foo = functools.partial(do, stuff)
Thanks @yaccz, here's a full example failure to the underlying problem:
import functools
def do_it(x):
assert x == 2
test_foo = functools.partial(do_it, x=1)
=================================== ERRORS ====================================
________________________ ERROR collecting test_foo.py _________________________
...\lib\inspect.py:752: in getargs
raise TypeError('{!r} is not a code object'.format(co))
E TypeError: <functools.partial object at 0x0000000003D37278> is not a code object
=============================== warning summary ===============================
WC2 X:\test_foo.py cannot collect 'test_foo' because it is not a function.
===================== 1 warnings, 1 error in 0.02 seconds =====================
@dimaqq, as an workaround, you can use @pytest.mark.parametrized to write equivalent code:
@pytest.mark.parametrized('foo', range(10))
def test_one(foo=123):
tmp = secret.secretObject()
tmp.init(...)
In which case you don't even need a test_all
anymore.
I think @hpk42 has mentioned to discourage "yield based tests" in the docs, and IMHO the parametrized version is clearer anyway. :smile:
Opened a new issue with a more specific report of the underlying problem.
Thanks @dimaqq for reporting the issue. :smile:
I created a PR which fixes this, feedback is welcome.
Originally reported by: Dima Tisnek (BitBucket: dimaqq, GitHub: dimaqq)
Traceback is far below.
Unfortunately I cannot yet create a minimum reproducible example, because everything works, if I remove propitiatory code.
Note that all tests pass (I can remove all asserts even), but there's still an internal error.
Below is the outline of the test: