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. The -k option selects tests by keyword expression matching their names.
- B. Yield inside a fixture separates setup (before yield) from teardown (after yield).
- C. Pytest cannot express an expected-to-fail test.correct
- D. Pytest uses plain assert statements with introspection for detailed failure messages.
Why: The selected statement is false. The other options are accurate statements about PyTest.
2. Which statement about PyTest is NOT correct?
- A. Pytest fixtures provide reusable setup via dependency injection into test function parameters.
- B. The -k option selects tests by keyword expression matching their names.
- C. The default fixture scope is session.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. Which of the following statements about PyTest is FALSE?
- A. Conftest.py shares fixtures and hooks across multiple test files without imports.
- B. Yield inside a fixture separates setup (before yield) from teardown (after yield).
- C. Fixture scope can be function, class, module, package, or session.
- D. Assertions in pytest must use self.assertEqual style methods.correct
Why: The selected statement is false. The other options are accurate statements about PyTest.
4. Identify the INCORRECT statement about PyTest:
- A. @pytest.mark.parametrize runs one test function with multiple argument sets.
- B. Conftest.py shares fixtures and hooks across multiple test files without imports.
- C. Markers like @pytest.mark.skip and @pytest.mark.xfail control expected outcomes.
- D. Pytest ships with parallel execution enabled without any plugin.correct
Why: The selected statement is false. The other options are accurate statements about PyTest.