Skip to main content
pytest
INTERVIEW QUESTIONS  /  pytest

pytest Interview Questions

Interviewing for a Python QA or SDET role? Practice with an AI that asks about pytest fixtures, parametrization, markers, conftest scope, and the plugin ecosystem, the topics Python automation interviews actually probe.

Free to start · 7-day trial on paid plans

What you’ll be asked.

pytest interviews focus on fixtures and their scopes (function, class, module, session), the conftest.py mechanism for sharing fixtures, and parametrization for data-driven tests. Expect questions on markers and test selection (-k, -m), mocking with monkeypatch and unittest.mock, assertion introspection, and fixture finalization with yield. Senior and SDET roles dig into writing custom plugins and hooks, parallelizing with pytest-xdist, generating reports (pytest-html, Allure), and structuring a maintainable Python automation framework.

Topics covered.

Key areas interviewers evaluate when asking about pytest.

Fixtures & Conftest

Fixture scopes, dependency injection, autouse, yield-based teardown, and sharing fixtures via conftest.py.

Parametrization

pytest.mark.parametrize, parametrized fixtures, indirect parametrization, and data-driven test design.

Markers & Selection

Custom markers, -k and -m expressions, skip/xfail, and organising large suites into fast feedback subsets.

Mocking & Monkeypatch

monkeypatch, unittest.mock, patching scope, and isolating units from network, time, and filesystem.

Plugins & Reporting

pytest-xdist parallelism, pytest-html and Allure reports, fixtures vs plugins, and writing custom hooks.

CI/CD Integration

Running pytest in GitHub Actions and Jenkins, JUnit XML output, coverage gates, and flaky-test reruns.

Sample Interview Questions

Questions based on real interview patterns. Practice answering these with AssertHired’s AI interviewer.

  1. 01

    Explain pytest fixture scopes. When would you use a session-scoped fixture over a function-scoped one?

  2. 02

    How does conftest.py work, and how does pytest discover fixtures across a test suite?

  3. 03

    What is the difference between parametrizing a test with @pytest.mark.parametrize and parametrizing a fixture?

  4. 04

    How do you mock an external HTTP call in pytest? Compare monkeypatch with unittest.mock.patch.

  5. 05

    A fixture needs to set up a database and guarantee cleanup even if the test fails. How do you implement that?

  6. 06

    How would you run only the tests tagged "smoke" and exclude "slow" tests in CI?

  7. 07

    How do you speed up a slow pytest suite? Walk me through pytest-xdist and what can break under parallelism.

  8. 08

    Describe how you would structure a Python test framework around pytest for an API + UI project.

How AssertHired works.

Three steps. No fluff. Designed specifically for QA engineers.

Step 01

Pick Your Focus

Choose from 6 QA-specific categories. Select your role, target company, and difficulty level to customize the experience.

Step 02

Interview with AI

Answer 5 realistic interview questions from an AI that understands QA workflows, test architecture, and engineering culture.

Step 03

Get Scored

Receive instant feedback scored across 4 dimensions: Technical Accuracy, Communication, Examples, and Depth of Knowledge.

Frequently Asked Questions

What pytest topics are most asked in interviews?

Fixtures and their scopes, conftest.py, parametrization, markers and test selection, mocking with monkeypatch/unittest.mock, and assertion introspection. SDET roles add custom plugins/hooks, parallel execution with pytest-xdist, and framework design.

Do I need to know unittest as well as pytest?

Knowing the differences helps. pytest can run unittest-style tests, but interviewers usually want to see idiomatic pytest, plain assert statements, fixtures instead of setUp/tearDown, and parametrization instead of loops.

Is pytest only for unit tests?

No. pytest is widely used for API, integration, and end-to-end suites (often with requests, Playwright for Python, or Selenium). Its fixture model makes it a strong base for full automation frameworks, which is why SDET interviews cover it.

Can I practice pytest interview questions on AssertHired?

Yes. The AI interviewer asks contextual pytest and Python automation questions with follow-ups, and scores you across Technical Accuracy, Communication, Examples, and Depth of Knowledge.

From the Blog

Related guides and tips to help you prepare.

Explore More Interview Prep Resources

Dive deeper into related QA interview topics.

FREE TOOLS  /  no signup

Free QA career tools, no account needed

Instant and private, everything runs in your browser. Try them before you sign up.

EXEC.NOW

Ready for Your pytest Interview?

Practice with AI that asks real pytest fixture, parametrization, and framework questions.

Join 1,200+ QA engineers already practicing with AssertHired.

Start your free QA interview
FREE.TO.START  ·  7.DAY.TRIAL ON PAID PLANS
Written by Aston Cook, Senior QA EngineerLast updated May 2026