fixtures

pytest mark parametrize a fixture

pytest mark parametrize a fixture Question: I want to test a function get_xyz(a, b, foo), where foo is a class. A foo_fixture is defined in a conftest.py like so: @pytest.fixture() def foo_fixture(): return Foo() The fixture simply returns a new instance of a class Foo. How would I parametrize this foo_fixture as an argument to …

Total answers: 1

Pytest missing 1 required positional argument with fixture

Pytest missing 1 required positional argument with fixture Question: I’m using vscode as IDE I have code a very simple usage of pytest fixture but it doesn’t working when basic example fixture found in the pytest documentation are working well : @pytest.fixture def declare_hexidict(): hd = hexidict() rvc = ReferenceValueCluster() rv = ReferenceValue(init=3) hd_var = …

Total answers: 2

How are pytest fixure scopes intended to work?

How are pytest fixure scopes intended to work? Question: I want to use pytest fixtures to prepare an object I want to use across a set of tests. I follow the documentation and create a fixture in something_fixture.py with its scope set to session like this: import pytest @pytest.fixture(scope="session") def something(): return ‘something’ Then in …

Total answers: 1

Using function scoped fixture to setup a class

Using function scoped fixture to setup a class Question: I have a fixture in conftest.py with a function scope. @pytest.fixture() def registration_setup( test_data, # fixture 1 credentials, # fixture 2 deployment # fixture 3 deployment_object # fixture 4 ): # pre-test cleanup do_cleanup() yield # post-test cleanup do_cleanup() I use it in a test class …

Total answers: 2

How can I provide a non-fixture pytest parameter via a custom decorator?

How can I provide a non-fixture pytest parameter via a custom decorator? Question: We have unit tests running via Pytest, which use a custom decorator to start up a context-managed mock echo server before each test, and provide its address to the test as an extra parameter. This works on Python 2. However, if we …

Total answers: 3

Pytest – dynamic resolution of fixtures' dependencies

Pytest – dynamic resolution of fixtures' dependencies Question: I cannot find a solution to alter fixtures dependency in any different way than this bellow. The problem is that I need to determine the dependencies basing on pytest.config.getoption argument, instead of what’s used here (variable resolved at module level). I need to get two modes of …

Total answers: 2

Pytest class scope parametrization

Pytest class scope parametrization Question: I have a couple of fixtures that do some initialization that is rather expensive. Some of those fixtures can take parameters, altering their behaviour slightly. Because these are so expensive, I wanted to do initialisation of them once per test class. However, it does not destroy and reinit the fixtures …

Total answers: 2

How to test the pytest fixture itself?

How to test the pytest fixture itself? Question: What is the proper way to test that the pytest fixture itself. Please do not confuse it with using fixture in tests. I want just tests the fixtures correctness by itself. When trying to call and execute them inside test I am facing: Fixture “app” called directly. …

Total answers: 1

pytest fixture – get value and avoid error "Fixture 'X' called directly"

pytest fixture – get value and avoid error "Fixture 'X' called directly" Question: I have updated pytest to 4.3.0 and now I need to rework test code since calling fixtures directly is deprecated. I have an issue with fixtures used in an unittest.TestCase, how do I get the value returned from the fixture and not …

Total answers: 3