mercredi 17 mai 2017

How to use fixtures in non-python py.test tests?

I have created a set of yaml-based test definitions using this example fro mdocs. All my tests work with database.

Currently I am creating database connection for each test, but that is not good. Database connection should be created once for the whole session. When using normal function-based tests, I would make a session-scoped fixture for database connection; but the approach I am using (with yaml-based tests) doesn't support fixtures at all. Here is how I tested that:

# conftest.py
...
@pytest.fixture(autouse=True)
def db_example():
    assert False

def pytest_collect_file(path, parent):
    ...  # here follows all the stuff from docs

When I run the above code, I don't get an AssertionError.

So the question is: 1. Which is the most simple way to enable fixtures for non-python tests? or 2. How to perform a session-level initialization (like setup_module) and store a value to some session-global place, but with no modules? All my python code is in conftest.py file.

Aucun commentaire:

Enregistrer un commentaire