PyTest interview questions — Medium

252 medium-level PyTest questions from our Automation Testing bank, each with the correct answer and an explanation of why it is correct.

What this covers

PyTest appears throughout Automation Testing interviews. At medium level, interviewers are typically checking that you have used it in practice: what you configured, what broke, and how you knew it worked. Work through these, then explain your answer out loud; the second part is what interviews actually test.

20 example questions

  1. 1. "Configuration files defining markers, paths, and options" — in PyTest, this describes which of the following?

    • A. Tmp_path.
    • B. Monkeypatch.
    • C. Capsys.
    • D. Pytest.ini / pyproject.toml.correct

    Why: pytest.ini / pyproject.toml: Configuration files defining markers, paths, and options.

  2. 2. "Runs only tests marked with the smoke marker" — in PyTest, this describes which of the following?

    • A. Monkeypatch.
    • B. Pytest.ini / pyproject.toml.
    • C. --maxfail=1.
    • D. Pytest -m smoke.correct

    Why: pytest -m smoke: Runs only tests marked with the smoke marker.

  3. 3. "Built-in fixture for safely patching attributes and env vars" — in PyTest, this describes which of the following?

    • A. --maxfail=1.
    • B. @pytest.fixture(autouse=True).
    • C. Monkeypatch.correct
    • D. Pytest -m smoke.

    Why: monkeypatch: Built-in fixture for safely patching attributes and env vars.

  4. 4. "Fixture applied automatically without being requested" — in PyTest, this describes which of the following?

    • A. Pytest -m smoke.
    • B. --maxfail=1.
    • C. Pytest-html.
    • D. @pytest.fixture(autouse=True).correct

    Why: @pytest.fixture(autouse=True): Fixture applied automatically without being requested.

  5. 5. Which statement correctly describes PyTest?

    • A. Pytest uses plain assert statements with introspection for detailed failure messages.correct
    • B. Assertions in pytest must use self.assertEqual style methods.
    • C. The default fixture scope is session.
    • D. Fixtures must be explicitly imported into every test file that uses them.

    Why: Assertion rewriting shows values of sub-expressions on failure.

  6. 6. "Fixture providing a unique temporary directory" — in PyTest, this describes which of the following?

    • A. Monkeypatch.
    • B. Pytest-html.
    • C. Pytest.ini / pyproject.toml.
    • D. Tmp_path.correct

    Why: tmp_path: Fixture providing a unique temporary directory.

  7. 7. During a code review, a reviewer asks: Which decorator runs a pytest test with multiple inputs?

    • A. @pytest.fixture.
    • B. @pytest.mark.parametrize.correct
    • C. @pytest.mark.skip.
    • D. @pytest.mark.usefixtures.

    Why: @pytest.mark.parametrize runs the test once per value.

  8. 8. "Plugin generating an HTML test report" — in PyTest, this describes which of the following?

    • A. Tmp_path.
    • B. Pytest -m smoke.
    • C. Pytest-html.correct
    • D. @pytest.fixture(autouse=True).

    Why: pytest-html: Plugin generating an HTML test report.

  9. 9. Identify the accurate statement about PyTest:

    • A. @pytest.mark.parametrize can only supply a single parameter value.
    • B. Fixtures must be explicitly imported into every test file that uses them.
    • C. Pytest fixtures provide reusable setup via dependency injection into test function parameters.correct
    • D. Pytest cannot express an expected-to-fail test.

    Why: A test requests a fixture simply by naming it as an argument.

  10. 10. Which of the following statements about PyTest is TRUE?

    • A. Pytest ships with parallel execution enabled without any plugin.
    • B. Fixture scope can be function, class, module, package, or session.correct
    • C. Pytest requires every test class to inherit from unittest.TestCase.
    • D. Assertions in pytest must use self.assertEqual style methods.

    Why: Broader scopes reuse expensive resources like DB connections.

  11. 11. "Fixture capturing stdout/stderr output" — in PyTest, this describes which of the following?

    • A. Capsys.correct
    • B. Tmp_path.
    • C. Pytest-html.
    • D. @pytest.fixture(autouse=True).

    Why: capsys: Fixture capturing stdout/stderr output.

  12. 12. In PyTest, which of the following is described as: "Fixture applied automatically without being requested"?

    • A. @pytest.fixture(autouse=True).correct
    • B. --maxfail=1.
    • C. Pytest.ini / pyproject.toml.
    • D. Pytest-html.

    Why: @pytest.fixture(autouse=True): Fixture applied automatically without being requested.

  13. 13. In the context of PyTest, which of the following is a correct statement?

    • A. The default fixture scope is session.
    • B. Pytest ships with parallel execution enabled without any plugin.
    • C. Assertions in pytest must use self.assertEqual style methods.
    • D. @pytest.mark.parametrize runs one test function with multiple argument sets.correct

    Why: Parametrize generates a separate test case per parameter tuple.

  14. 14. In PyTest, which of the following is described as: "Runs only tests marked with the smoke marker"?

    • A. @pytest.fixture(autouse=True).
    • B. --maxfail=1.
    • C. Pytest -m smoke.correct
    • D. Capsys.

    Why: pytest -m smoke: Runs only tests marked with the smoke marker.

  15. 15. Which PyTest concept matches this description: "Runs only tests marked with the smoke marker"?

    • A. --maxfail=1.
    • B. @pytest.fixture(autouse=True).
    • C. Monkeypatch.
    • D. Pytest -m smoke.correct

    Why: pytest -m smoke: Runs only tests marked with the smoke marker.

  16. 16. Which PyTest concept matches this description: "Fixture applied automatically without being requested"?

    • A. Pytest.ini / pyproject.toml.
    • B. @pytest.fixture(autouse=True).correct
    • C. Pytest -m smoke.
    • D. Tmp_path.

    Why: @pytest.fixture(autouse=True): Fixture applied automatically without being requested.

  17. 17. In PyTest, which of the following is described as: "Configuration files defining markers, paths, and options"?

    • A. Tmp_path.
    • B. --maxfail=1.
    • C. Pytest-html.
    • D. Pytest.ini / pyproject.toml.correct

    Why: pytest.ini / pyproject.toml: Configuration files defining markers, paths, and options.

  18. 18. Which PyTest concept matches this description: "CLI option stopping the run after the first failure"?

    • A. --maxfail=1.correct
    • B. Capsys.
    • C. Pytest.ini / pyproject.toml.
    • D. @pytest.fixture(autouse=True).

    Why: --maxfail=1: CLI option stopping the run after the first failure.

  19. 19. Which PyTest concept matches this description: "Built-in fixture for safely patching attributes and env vars"?

    • A. Pytest-html.
    • B. Capsys.
    • C. --maxfail=1.
    • D. Monkeypatch.correct

    Why: monkeypatch: Built-in fixture for safely patching attributes and env vars.

  20. 20. Which PyTest concept matches this description: "Configuration files defining markers, paths, and options"?

    • A. Tmp_path.
    • B. --maxfail=1.
    • C. @pytest.fixture(autouse=True).
    • D. Pytest.ini / pyproject.toml.correct

    Why: pytest.ini / pyproject.toml: Configuration files defining markers, paths, and options.

Related Automation Testing topics