Reputation: 11
import pytest
@pytest.fixture()
def my_fixture():
print('begin')
print('#####################################')
class TestA():
# @pytest.mark.usefixtures('my_fixture')
def test_a(self, my_fixture, a):
print("{}".format(a))
if __name__ == '__main__':
pytest.main()
E fixture 'a' not found
> available fixtures: cache, capfd, capfdbinary, caplog, capsys, capsysbinary, doctest_namespace, extra, include_metadata_in_junit_xml, login_and_exit, metadata, monkeypatch, my_fixture, pytestconfig, record_property, record_testsuite_property, record_xml_attribute, recwarn, tmp_path, tmp_path_factory, tmpdir, tmpdir_factory
> use 'pytest --fixtures [testpath]' for help on them.
Upvotes: 1
Views: 2312
Reputation: 1541
If you uncomment decorator above test_a
and remove parameters it will work. Also you can remove redundant parentheses from class definition and fixture decorator:
import pytest
@pytest.fixture
def my_fixture():
print('Inside fixture my_fixture.')
@pytest.fixture
def a():
print('Inside fixture a . Returning value 3 for a')
return 3
class Test:
@pytest.mark.usefixtures('my_fixture', 'a')
def test_a(self, a):
print("Inside test. Argument has value: {}".format(a))
if __name__ == '__main__':
pytest.main()
Upvotes: 2