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. Regarding PyTest, which of the following is a false statement?
- A. Pytest-xdist enables parallel test execution with the -n option.
- B. Assertions in pytest must use self.assertEqual style methods.correct
- C. Conftest.py shares fixtures and hooks across multiple test files without imports.
- D. Pytest.raises is a context manager asserting that a block raises a given exception.
Why: The selected statement is false. The other options are accurate statements about PyTest.
2. Which statement about PyTest is NOT correct?
- A. The -k option selects tests by keyword expression matching their names.
- B. Pytest fixtures provide reusable setup via dependency injection into test function parameters.
- C. Assertions in pytest must use self.assertEqual style methods.correct
- D. Yield inside a fixture separates setup (before yield) from teardown (after yield).
Why: The selected statement is false. The other options are accurate statements about PyTest.
3. Identify the INCORRECT statement about PyTest:
- A. @pytest.mark.parametrize can only supply a single parameter value.correct
- B. Fixture scope can be function, class, module, package, or session.
- C. Pytest uses plain assert statements with introspection for detailed failure messages.
- 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. 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.