Test collection fails when using pytest.mark.usefixtures and a test function is a classmethod
See original GitHub issueThis minimal example using django TestCase class causes an error on collection:
from django.test import TestCase
import pytest
@pytest.fixture
def harry_potter(request):
return 1
@pytest.mark.usefixtures('harry_potter')
class FooTestCase(TestCase):
@classmethod
def test_foo(cls):
assert 1
The output of running pytest
is as such:
platform linux -- Python 3.6.5, pytest-3.6.1, py-1.5.3, pluggy-0.6.0
Django settings: project.settings.development (from ini file)
rootdir: /users/username/project/src, inifile: pytest.ini
plugins: django-3.2.1, celery-4.1.1
collected 11 items / 1 errors
================================================================================================================== ERRORS ===================================================================================================================
_______________________________________________________________________________________________ ERROR collecting tests/fooTestCase.py ________________________________________________________________________________________________
../../../../../.virtualenvs/myvenv/lib/python3.6/site-packages/_pytest/runner.py:198: in __init__
self.result = func()
../../../../../.virtualenvs/myvenv/lib/python3.6/site-packages/_pytest/runner.py:419: in <lambda>
call = CallInfo(lambda: list(collector.collect()), "collect")
../../../../../.virtualenvs/myvenv/lib/python3.6/site-packages/_pytest/unittest.py:57: in collect
transfer_markers(funcobj, cls, module)
../../../../../.virtualenvs/myvenv/lib/python3.6/site-packages/_pytest/mark/structures.py:265: in transfer_markers
store_legacy_markinfo(funcobj, mark)
../../../../../.virtualenvs/myvenv/lib/python3.6/site-packages/_pytest/mark/structures.py:248: in store_legacy_markinfo
setattr(func, mark.name, holder)
E AttributeError: 'method' object has no attribute 'usefixtures'
OS: Fedora 27
(See log output for everything else)
If no test function is a classmethod
it works alright. I don’t know if this is a feature. Nothing seems to imply that.
Thank you!
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
pytest fixtures: explicit, modular, scalable
fixtures have explicit names and are activated by declaring their use from test functions, modules, classes or whole projects. fixtures are implemented in...
Read more >Pytest fixture for a class through self not as method argument
I wanted to call a fixture once per test class and re-use the value in test ... @pytest.mark.usefixtures("google") class TestGoogle: def ...
Read more >pytest Documentation - Read the Docs
“How to mark test functions with attributes” for information on the pytest.mark mechanism. • “Fixtures reference” for providing a functional ...
Read more >Working with custom markers — pytest documentation
Marking test functions and selecting them for a run¶. You can “mark” a test function with custom metadata like this: # content of...
Read more >Effective Python Testing With Pytest
pytest is a feature-rich, plugin-based ecosystem for testing your Python code. If you haven't had the pleasure of using pytest yet, then you're ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Yeah alright ^^. I’ll submit a PR soon. Thanks.
Fix will be available in pytest 4.1.