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.

No account needed · Scored in under a minute against a senior rubric

What do interviewers ask about pytest?

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.

What do pytest interviewers ask at junior, mid and senior level?

The same tool, three different interviews. Find your row before you prepare.

pytest interview questions by level: junior, mid-level and senior
JuniorWhat interviewers probeTest discovery, plain assert, fixtures, and the difference between pytest and unittest.Typical questionHow does pytest know which functions are tests, and what happens to a function named check_login?
Mid-levelWhat interviewers probeFixture scopes and dependency, parametrize, markers, conftest.py layering, and mocking with monkeypatch.Typical questionWhen would you use a session-scoped fixture, and what risk does it introduce?
SeniorWhat interviewers probePlugin ecosystem choices, parallel runs with xdist, test architecture across a monorepo, and CI reliability.Typical questionHow would you make a 10,000-test pytest suite run in under ten minutes without hiding flakiness?

Which pytest topics come up most?

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.

What are common pytest 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 does AssertHired help you practice pytest questions?

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 500+ QA engineers already practicing with AssertHired.

Question 1 · Automation · Mid-levellive scoring

A test passes locally but fails in CI about one run in five. Walk me through what you check first, and why.

Scored on the same four dimensions as the real thing: Technical accuracy · Coverage · Clarity · Best practices.

Rather skip ahead? Create a free account

FREE.TO.START  ·  7.DAY.TRIAL ON PAID PLANS