PyTest interview questions — Easy
125 easy-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 easy level, interviewers are typically checking that you know the fundamentals and can describe them precisely — definitions, defaults, and the basic mechanics. Work through these, then explain your answer out loud; the second part is what interviews actually test.
20 example questions
1. In the context of PyTest, @pytest.fixture(autouse=True) is best described as:
- A. Fixture capturing stdout/stderr output.
- B. Runs only tests marked with the smoke marker.
- C. Fixture applied automatically without being requested.correct
- D. CLI option stopping the run after the first failure.
Why: @pytest.fixture(autouse=True): Fixture applied automatically without being requested.
2. On a release readiness call: In pytest, a fixture's primary purpose is:
- A. To assert equality.
- B. Reusable setup/teardown injected by parameter name.correct
- C. To skip a test.
- D. To time execution.
Why: Fixtures provide reusable setup/teardown via dependency injection.
3. What is the purpose of pytest.ini / pyproject.toml in PyTest?
- A. CLI option stopping the run after the first failure.
- B. Configuration files defining markers, paths, and options.correct
- C. Fixture capturing stdout/stderr output.
- D. Runs only tests marked with the smoke marker.
Why: pytest.ini / pyproject.toml: Configuration files defining markers, paths, and options.
4. In PyTest, what does pytest.ini / pyproject.toml do or refer to?
- A. CLI option stopping the run after the first failure.
- B. Fixture applied automatically without being requested.
- C. Fixture providing a unique temporary directory.
- D. Configuration files defining markers, paths, and options.correct
Why: pytest.ini / pyproject.toml: Configuration files defining markers, paths, and options.
5. In PyTest, what does @pytest.fixture(autouse=True) do or refer to?
- A. Fixture applied automatically without being requested.correct
- B. Runs only tests marked with the smoke marker.
- C. Plugin generating an HTML test report.
- D. Built-in fixture for safely patching attributes and env vars.
Why: @pytest.fixture(autouse=True): Fixture applied automatically without being requested.
6. Which of the following best describes pytest.ini / pyproject.toml in PyTest?
- A. Configuration files defining markers, paths, and options.correct
- B. Fixture capturing stdout/stderr output.
- C. Built-in fixture for safely patching attributes and env vars.
- D. Fixture applied automatically without being requested.
Why: pytest.ini / pyproject.toml: Configuration files defining markers, paths, and options.
7. Which of the following best describes @pytest.fixture(autouse=True) in PyTest?
- A. CLI option stopping the run after the first failure.
- B. Runs only tests marked with the smoke marker.
- C. Fixture providing a unique temporary directory.
- D. Fixture applied automatically without being requested.correct
Why: @pytest.fixture(autouse=True): Fixture applied automatically without being requested.
8. Which of the following best describes pytest -m smoke in PyTest?
- A. Built-in fixture for safely patching attributes and env vars.
- B. Fixture providing a unique temporary directory.
- C. Plugin generating an HTML test report.
- D. Runs only tests marked with the smoke marker.correct
Why: pytest -m smoke: Runs only tests marked with the smoke marker.
9. What is the purpose of @pytest.fixture(autouse=True) in PyTest?
- A. CLI option stopping the run after the first failure.
- B. Fixture providing a unique temporary directory.
- C. Built-in fixture for safely patching attributes and env vars.
- D. Fixture applied automatically without being requested.correct
Why: @pytest.fixture(autouse=True): Fixture applied automatically without being requested.
10. Which of the following best describes monkeypatch in PyTest?
- A. Fixture applied automatically without being requested.
- B. Built-in fixture for safely patching attributes and env vars.correct
- C. Fixture providing a unique temporary directory.
- D. CLI option stopping the run after the first failure.
Why: monkeypatch: Built-in fixture for safely patching attributes and env vars.
11. In PyTest, what does pytest -m smoke do or refer to?
- A. Configuration files defining markers, paths, and options.
- B. Runs only tests marked with the smoke marker.correct
- C. Fixture providing a unique temporary directory.
- D. Plugin generating an HTML test report.
Why: pytest -m smoke: Runs only tests marked with the smoke marker.
12. What is the purpose of monkeypatch in PyTest?
- A. Built-in fixture for safely patching attributes and env vars.correct
- B. CLI option stopping the run after the first failure.
- C. Configuration files defining markers, paths, and options.
- D. Fixture providing a unique temporary directory.
Why: monkeypatch: Built-in fixture for safely patching attributes and env vars.
13. What is the purpose of pytest -m smoke in PyTest?
- A. Built-in fixture for safely patching attributes and env vars.
- B. Fixture providing a unique temporary directory.
- C. Runs only tests marked with the smoke marker.correct
- D. CLI option stopping the run after the first failure.
Why: pytest -m smoke: Runs only tests marked with the smoke marker.
14. What is the purpose of --maxfail=1 in PyTest?
- A. Configuration files defining markers, paths, and options.
- B. Built-in fixture for safely patching attributes and env vars.
- C. Fixture capturing stdout/stderr output.
- D. CLI option stopping the run after the first failure.correct
Why: --maxfail=1: CLI option stopping the run after the first failure.
15. In pytest, what is the primary purpose of a fixture?
- A. To assert a value equals another.
- B. To provide reusable setup/teardown and test dependencies via dependency injection.correct
- C. To skip a test.
- D. To measure execution time.
Why: pytest fixtures supply reusable setup (and teardown) and are injected into tests by parameter name, replacing setup/teardown boilerplate.
16. In PyTest, what does monkeypatch do or refer to?
- A. CLI option stopping the run after the first failure.
- B. Built-in fixture for safely patching attributes and env vars.correct
- C. Fixture providing a unique temporary directory.
- D. Plugin generating an HTML test report.
Why: monkeypatch: Built-in fixture for safely patching attributes and env vars.
17. Which of the following best describes --maxfail=1 in PyTest?
- A. Fixture applied automatically without being requested.
- B. Runs only tests marked with the smoke marker.
- C. Plugin generating an HTML test report.
- D. CLI option stopping the run after the first failure.correct
Why: --maxfail=1: CLI option stopping the run after the first failure.
18. In PyTest, what does capsys do or refer to?
- A. Fixture capturing stdout/stderr output.correct
- B. Configuration files defining markers, paths, and options.
- C. Runs only tests marked with the smoke marker.
- D. Fixture providing a unique temporary directory.
Why: capsys: Fixture capturing stdout/stderr output.
19. In PyTest, what does tmp_path do or refer to?
- A. Built-in fixture for safely patching attributes and env vars.
- B. CLI option stopping the run after the first failure.
- C. Plugin generating an HTML test report.
- D. Fixture providing a unique temporary directory.correct
Why: tmp_path: Fixture providing a unique temporary directory.
20. What is the purpose of pytest-html in PyTest?
- A. Fixture applied automatically without being requested.
- B. Plugin generating an HTML test report.correct
- C. Built-in fixture for safely patching attributes and env vars.
- D. Configuration files defining markers, paths, and options.
Why: pytest-html: Plugin generating an HTML test report.