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.
- 01
Explain pytest fixture scopes. When would you use a session-scoped fixture over a function-scoped one?
- 02
How does conftest.py work, and how does pytest discover fixtures across a test suite?
- 03
What is the difference between parametrizing a test with @pytest.mark.parametrize and parametrizing a fixture?
- 04
How do you mock an external HTTP call in pytest? Compare monkeypatch with unittest.mock.patch.
- 05
A fixture needs to set up a database and guarantee cleanup even if the test fails. How do you implement that?
- 06
How would you run only the tests tagged "smoke" and exclude "slow" tests in CI?
- 07
How do you speed up a slow pytest suite? Walk me through pytest-xdist and what can break under parallelism.
- 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.
Pick Your Focus
Choose from 6 QA-specific categories. Select your role, target company, and difficulty level to customize the experience.
Interview with AI
Answer 5 realistic interview questions from an AI that understands QA workflows, test architecture, and engineering culture.
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 QA career tools, no account needed
Instant and private, everything runs in your browser. Try them before you sign up.
QA Resume Checker
Instant 0-100 score on automation keywords, impact, and ATS formatting.
QA Cover Letter Generator
A tailored 3-paragraph QA cover letter from your resume and a job post.
QA Application Tracker
Drag-and-drop kanban to track every QA application from Applied to Offer.
QA Take-Home Test Generator
A realistic take-home assignment with a scenario, tasks, and a rubric.
QA LinkedIn Headline Generator
A recruiter-searchable headline, About section, and skills list.
QA STAR Story Builder
Structure a QA behavioral answer with the STAR method and instant checks.
QA Bug Report Generator
Build a clean, reproducible bug report for Markdown, Jira, or plain text.
Boundary Value Analysis Generator
Generate boundary value and equivalence partitioning test cases from a range.
QA Metrics Calculator
Calculate DRE, defect leakage, defect density, and pass rate with interpretation.
QA Test Plan Generator
Build a structured test plan (scope, approach, criteria, risks) in Markdown.
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