Skip to content

PyTest interview questions — Hard

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

This topic slice is available to practise but is not yet part of our indexed set.

What this covers

PyTest appears throughout Automation Testing interviews. At hard level, interviewers are typically checking depth under pressure — edge cases, failure modes, performance characteristics, and the trade-offs you accepted. Work through these, then explain your answer out loud; the second part is what interviews actually test.

4 example questions

  1. 1. Regarding PyTest, which of the following is a false statement?

    • A. Pytest.raises is a context manager asserting that a block raises a given exception.
    • B. Pytest-xdist enables parallel test execution with the -n option.
    • C. @pytest.mark.parametrize can only supply a single parameter value.correct
    • D. Fixture scope can be function, class, module, package, or session.

    Why: The selected statement is false. The other options are accurate statements about PyTest.

  2. 2. Which statement about PyTest is NOT correct?

    • A. Pytest.raises is a context manager asserting that a block raises a given exception.
    • B. Markers like @pytest.mark.skip and @pytest.mark.xfail control expected outcomes.
    • C. Conftest.py shares fixtures and hooks across multiple test files without imports.
    • D. @pytest.mark.parametrize can only supply a single parameter value.correct

    Why: The selected statement is false. The other options are accurate statements about PyTest.

  3. 3. Which of the following statements about PyTest is FALSE?

    • A. Pytest-xdist enables parallel test execution with the -n option.
    • B. Yield inside a fixture separates setup (before yield) from teardown (after yield).
    • C. The default fixture scope is session.correct
    • D. Pytest fixtures provide reusable setup via dependency injection into test function parameters.

    Why: The selected statement is false. The other options are accurate statements about PyTest.

  4. 4. Identify the INCORRECT statement about PyTest:

    • A. Conftest.py shares fixtures and hooks across multiple test files without imports.
    • B. Markers like @pytest.mark.skip and @pytest.mark.xfail control expected outcomes.
    • C. Yield inside a fixture separates setup (before yield) from teardown (after yield).
    • D. The default fixture scope is session.correct

    Why: The selected statement is false. The other options are accurate statements about PyTest.

Related Automation Testing topics