Repaso
EspaƱol
TestingIntermediateTST-14

What is conftest.py for in pytest?

Options

  1. Configuring the linters of the whole project
  2. Sharing fixtures and hooks with the tests below it (Correct option)
  3. Storing the test data files of the project
  4. Defining the CI pipelines of the repository

Answer

Sharing fixtures and hooks with all tests in that directory and below, without importing them

Why

Fixtures defined in a conftest.py file are automatically available to every test in the same folder and its subfolders. You don't import them.

Typical content: database fixtures, a test client for your app, shared fake objects.

General pytest settings go in pyproject.toml or pytest.ini.

Remember

conftest.py = shared fixtures for a folder of tests.

Key terms

Practice this question in Repaso