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 PyTest, what does pytest.ini / pyproject.toml do or refer to?
- A. Configuration files defining markers, paths, and options.correct
- B. Built-in fixture for safely patching attributes and env vars.
- C. Fixture applied automatically without being requested.
- D. Fixture providing a unique temporary directory.
Why: pytest.ini / pyproject.toml: Configuration files defining markers, paths, and options.
2. What is the purpose of pytest.ini / pyproject.toml in PyTest?
- A. Configuration files defining markers, paths, and options.correct
- B. Fixture providing a unique temporary directory.
- C. Built-in fixture for safely patching attributes and env vars.
- D. Fixture capturing stdout/stderr output.
Why: pytest.ini / pyproject.toml: Configuration files defining markers, paths, and options.
3. In PyTest, what does @pytest.fixture(autouse=True) do or refer to?
- A. Plugin generating an HTML test report.
- B. Fixture applied automatically without being requested.correct
- C. Configuration files defining markers, paths, and options.
- D. Built-in fixture for safely patching attributes and env vars.
Why: @pytest.fixture(autouse=True): Fixture applied automatically without being requested.
4. Which of the following best describes pytest.ini / pyproject.toml in PyTest?
- A. Configuration files defining markers, paths, and options.correct
- B. Built-in fixture for safely patching attributes and env vars.
- C. CLI option stopping the run after the first failure.
- D. Runs only tests marked with the smoke marker.
Why: pytest.ini / pyproject.toml: Configuration files defining markers, paths, and options.
5. In a CI/CD pipeline review, consider this: 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.
6. Which of the following best describes @pytest.fixture(autouse=True) in PyTest?
- A. CLI option stopping the run after the first failure.
- B. Fixture applied automatically without being requested.correct
- C. Plugin generating an HTML test report.
- D. Fixture providing a unique temporary directory.
Why: @pytest.fixture(autouse=True): Fixture applied automatically without being requested.
7. In the context of PyTest, @pytest.fixture(autouse=True) is best described as:
- A. Fixture applied automatically without being requested.correct
- B. Fixture capturing stdout/stderr output.
- C. CLI option stopping the run after the first failure.
- D. Plugin generating an HTML test report.
Why: @pytest.fixture(autouse=True): Fixture applied automatically without being requested.
8. What is the purpose of @pytest.fixture(autouse=True) in PyTest?
- A. Fixture capturing stdout/stderr output.
- B. Fixture applied automatically without being requested.correct
- C. Runs only tests marked with the smoke marker.
- D. Configuration files defining markers, paths, and options.
Why: @pytest.fixture(autouse=True): Fixture applied automatically without being requested.
9. Which of the following best describes pytest -m smoke in PyTest?
- A. Fixture providing a unique temporary directory.
- B. CLI option stopping the run after the first failure.
- C. Fixture applied automatically without being requested.
- D. Runs only tests marked with the smoke marker.correct
Why: pytest -m smoke: Runs only tests marked with the smoke marker.
10. What is the purpose of --maxfail=1 in PyTest?
- A. Configuration files defining markers, paths, and options.
- B. CLI option stopping the run after the first failure.correct
- C. Plugin generating an HTML test report.
- D. Built-in fixture for safely patching attributes and env vars.
Why: --maxfail=1: CLI option stopping the run after the first failure.
11. 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.
12. In PyTest, what does monkeypatch do or refer to?
- A. Built-in fixture for safely patching attributes and env vars.correct
- B. Plugin generating an HTML test report.
- C. Runs only tests marked with the smoke marker.
- D. Configuration files defining markers, paths, and options.
Why: monkeypatch: Built-in fixture for safely patching attributes and env vars.
13. What is the purpose of pytest -m smoke in PyTest?
- A. CLI option stopping the run after the first failure.
- B. Runs only tests marked with the smoke marker.correct
- C. Configuration files defining markers, paths, and options.
- D. Fixture providing a unique temporary directory.
Why: pytest -m smoke: Runs only tests marked with the smoke marker.
14. What is the purpose of monkeypatch in PyTest?
- A. Fixture providing a unique temporary directory.
- B. Built-in fixture for safely patching attributes and env vars.correct
- C. CLI option stopping the run after the first failure.
- D. Runs only tests marked with the smoke marker.
Why: monkeypatch: Built-in fixture for safely patching attributes and env vars.
15. 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.
16. In PyTest, what does pytest -m smoke 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.
- C. Runs only tests marked with the smoke marker.correct
- D. Plugin generating an HTML test report.
Why: pytest -m smoke: Runs only tests marked with the smoke marker.
17. Which of the following best describes --maxfail=1 in PyTest?
- A. Fixture providing a unique temporary directory.
- B. CLI option stopping the run after the first failure.correct
- C. Runs only tests marked with the smoke marker.
- D. Fixture capturing stdout/stderr output.
Why: --maxfail=1: CLI option stopping the run after the first failure.
18. What is the purpose of capsys in PyTest?
- A. Plugin generating an HTML test report.
- B. Runs only tests marked with the smoke marker.
- C. Fixture capturing stdout/stderr output.correct
- D. Fixture providing a unique temporary directory.
Why: capsys: Fixture capturing stdout/stderr output.
19. Which of the following best describes capsys in PyTest?
- A. Fixture providing a unique temporary directory.
- B. Fixture capturing stdout/stderr output.correct
- C. Plugin generating an HTML test report.
- D. Fixture applied automatically without being requested.
Why: capsys: Fixture capturing stdout/stderr output.
20. Which of the following best describes tmp_path in PyTest?
- A. CLI option stopping the run after the first failure.
- B. Fixture providing a unique temporary directory.correct
- C. Fixture capturing stdout/stderr output.
- D. Built-in fixture for safely patching attributes and env vars.
Why: tmp_path: Fixture providing a unique temporary directory.