-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Closed
Labels
topic: fixturesanything involving fixtures directly or indirectlyanything involving fixtures directly or indirectlytype: questiongeneral question, might be closed after 2 weeks of inactivitygeneral question, might be closed after 2 weeks of inactivity
Description
# conftest.py
import pytest
@pytest.fixture(scope='session', autouse=True)
def thing():
raise Exception('thing ran!')
def pytest_collect_file(path, parent):
return FooItem(path, parent)
class FooItem(pytest.Item, pytest.File):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.add_marker('foo')
def runtest(self):
raise Exception(str(self.fspath) + ' ran!')
# test_foo.py
def test_whatever():
pass
If I run test_foo.py
, I get a failure (from the injected FooItem
) and an error (from the exception in the thing
fixture, which ran because it is autouse=True
).
$ venv/bin/pytest test_foo.py
...
==================== 1 failed, 1 warning, 1 error in 0.15s =====================
However, if I just want to run the FooItem
(which has its own marker, 'foo'
), the autouse
fixture is skipped:
$ venv/bin/pytest -m foo test_foo.py
...
================== 1 failed, 1 deselected, 1 warning in 0.17s ==================
- Note that the results show a failure from the
FooItem
, not an error from thething
fixture.
Here's my venv's pip list
:
Package Version
------------------ -------
attrs 19.3.0
importlib-metadata 1.5.0
more-itertools 8.2.0
packaging 20.1
pip 19.2.3
pluggy 0.13.1
py 1.8.1
pyparsing 2.4.6
pytest 5.3.5
setuptools 41.2.0
six 1.14.0
wcwidth 0.1.8
zipp 2.1.0
I'm on macOS 10.13.6.
Metadata
Metadata
Assignees
Labels
topic: fixturesanything involving fixtures directly or indirectlyanything involving fixtures directly or indirectlytype: questiongeneral question, might be closed after 2 weeks of inactivitygeneral question, might be closed after 2 weeks of inactivity