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've written some code to dynamically generate some test cases on a unittest.TestCase. Pytest correctly executes these test cases, but wrongly identifies some of the setup code as a test case, and can't execute it. I'd like pytest to ignore this setup code.
$ python3 -m pytest
=================================== test session starts ====================================
platform darwin -- Python 3.3.2 -- pytest-2.3.5
collected 9 items
test_tennis.py .
test_unittest_tennis.py .......E
========================================== ERRORS ==========================================
_______________________________ ERROR at setup of test_case ________________________________
file ./test_unittest_tennis.py, line 36
def foo(self):
fixture 'self' not found
available fixtures: capfd, monkeypatch, pytestconfig, recwarn, tmpdir, capsys
use 'py.test --fixtures [testpath]' for help on them.
./test_unittest_tennis.py:36
============================ 8 passed, 1 error in 0.08 seconds =============================
The "foo" method on line 36 is not a test case and pytest should not try to execute it. The source code is attached.
Original comment byholger krekel (BitBucket: hpk42, GitHub: hpk42):
you need to add del test_name, test_case as final lines. pytest otherwise sees test_case as a test function at module scope. You could see withpy.test -v or py.test --collectonly what tests actually were generated.
I'd recommend to look into using parametrization (many examples in the fixture docs), however. If your goal is to have test code that executes on unittest, nose and py.test then of course that's doable but you are missing out on a lot of nice pytest features :)
(sidenote: i am gone for about 2 weeks of holiday, see you! :)
Originally reported by: Emily Bache (BitBucket: emilybache, GitHub: emilybache)
I've written some code to dynamically generate some test cases on a unittest.TestCase. Pytest correctly executes these test cases, but wrongly identifies some of the setup code as a test case, and can't execute it. I'd like pytest to ignore this setup code.
$ python3 -m pytest
=================================== test session starts ====================================
platform darwin -- Python 3.3.2 -- pytest-2.3.5
collected 9 items
test_tennis.py .
test_unittest_tennis.py .......E
========================================== ERRORS ==========================================
_______________________________ ERROR at setup of test_case ________________________________
file ./test_unittest_tennis.py, line 36
def foo(self):
fixture 'self' not found
available fixtures: capfd, monkeypatch, pytestconfig, recwarn, tmpdir, capsys
use 'py.test --fixtures [testpath]' for help on them.
./test_unittest_tennis.py:36
============================ 8 passed, 1 error in 0.08 seconds =============================
The "foo" method on line 36 is not a test case and pytest should not try to execute it. The source code is attached.
The text was updated successfully, but these errors were encountered: