Python Interview Questions for Testers
pytest interview questions for QA roles focus on fixtures and their scopes, parametrize, markers and conftest.py. Python interviews add data structures, OOP and the requests library. Practice with an AI interviewer that asks all of them, then go deeper on pytest.
A test passes locally but fails in CI about one run in five. Walk me through what you check first, and why.
This single answer is scored on four dimensions: Technical accuracy · Coverage · Clarity · Best practices.
No account needed · Scored in under a minute against a senior rubric
What do interviewers ask about Python?
Python interviews for testers cover data structures (lists, dicts, sets, tuples), OOP concepts, string manipulation, file handling, and the pytest framework in depth. Expect questions on pytest fixtures, parametrize decorators, conftest.py organization, the requests library for API testing, and structuring Python test projects. Understanding list comprehensions, generators, and decorators sets strong candidates apart.
Learning Python properly? Read a free lesson from QA Interview Vault, or see the course.
What do Python interviewers ask at junior, mid and senior level?
The same tool, three different interviews. Find your row before you prepare.
| Level | What interviewers probe | Typical question |
|---|---|---|
| Junior | What interviewers probepytest basics, assert statements, fixtures, test discovery, and the difference between unittest and pytest. | Typical questionHow does pytest find your tests, and what naming rules does it rely on? |
| Mid-level | What interviewers probeParametrisation, fixture scopes, mocking with unittest.mock, and structuring tests for a Django or FastAPI service. | Typical questionHow would you test a function that calls an external API without hitting the network? |
| Senior | What interviewers probeTest suite architecture, property-based testing, plugin choices, and running Python tests reliably in CI at scale. | Typical questionWhere would property-based testing pay off in a Python service, and where would it be a waste? |
Which Python topics come up most?
Key areas interviewers evaluate when asking about python for testing.
Python Fundamentals
Data structures, string manipulation, comprehensions, generators, and the Pythonic patterns testers use daily.
pytest Framework
Fixtures, parametrize, markers, conftest.py, plugins, and structuring test suites with pytest.
OOP for Testing
Classes, inheritance, dunder methods, and applying OOP to page objects and test utilities.
API Testing (requests)
HTTP requests with the requests library, session management, response validation, and API test patterns.
File & Data Handling
Reading CSV/JSON test data, environment variables, config files, and test data management in Python.
Project Structure
Virtual environments, pip/poetry, project layout, conftest hierarchy, and CI/CD integration.
What are common Python interview questions and answers?
Each answer is the shape of a strong response, not a script to memorise. Read it, then say it out loud in your own words.
- 01Junior
Explain pytest fixtures. How do fixture scopes (function, class, module, session) affect test isolation?
A fixture is a function marked @pytest.fixture that a test requests by naming it as an argument, and pytest passes in its value. Scope decides how long it lives: function, the default, builds it for every test, while class, module, package and session share one instance across that wider group. A wider scope is faster but shares state, so keep anything a test can change at function scope. Put teardown code after a yield in the fixture.
- 02Mid-level
How does conftest.py work in pytest? How would you organize conftest files in a large test project?
Fixtures in a conftest.py are available to every test in that directory and below it, with no import. Each directory can have its own conftest.py that adds to the fixtures from its parents, and a fixture with the same name lower down overrides the one above. In a large project, keep shared fixtures such as the API client and config in the top-level conftest.py, and put fixtures only one area needs in that area's folder.
- 03Junior
How would you use pytest.mark.parametrize to test a function with several input and output pairs?
Pass the argument names and a list of tuples, for example @pytest.mark.parametrize("test_input,expected", [("3+5", 8), ("2+4", 6)]), and give the test function those same parameters. pytest runs the test once per tuple and reports each case separately, with an id such as test_eval[3+5-8]. To mark a single case, wrap it in pytest.param, for example with marks=pytest.mark.xfail.
- 04Mid-level
How would you use the requests library to test a REST API, including authentication and response validation?
Use a requests.Session so auth, headers and cookies carry across calls, and set auth=(user, password) or an Authorization header on it. Always pass a timeout, because requests never times out unless you tell it to. Then assert r.status_code against the exact code you expect, read the body with r.json() and check the fields that matter. raise_for_status() suits setup code, but in the test itself an explicit status assertion gives a clearer failure.
- 05Mid-level
What are Python decorators? How would you write a custom decorator for test retry logic?
A decorator is a function that takes a function and returns a new one, applied with the @ syntax. A retry decorator wraps the call in a loop, catches AssertionError or a named exception, waits, and re-raises after the last attempt. Use functools.wraps on the inner function so the wrapper keeps the original name and docstring. Then say that retries hide flakiness, so log every retry and fix the cause.
- 06Mid-level
Compare pytest with unittest. Why has pytest become the standard for test automation?
unittest ships with Python and uses classes that subclass TestCase, with setUp and tearDown and assertion methods such as assertEqual. pytest lets you write plain functions with the plain assert statement, and rewrites it to show the compared values on failure. It adds fixtures, parametrize and a plugin system. Because pytest also runs existing unittest suites, a team can move across gradually, though pytest fixtures (other than autouse ones) and parametrize do not work inside TestCase classes.
- 07Senior
How would you structure a Python test automation project with page objects, fixtures, and config management?
Keep tests apart from framework code: a pages package for page objects, a package for API clients and helpers, and tests grouped by feature. Put shared fixtures such as the browser or API session and a config object in conftest.py, and pytest settings in pytest.ini or pyproject.toml. Read environment values like base URLs from environment variables or a command-line option added with pytest_addoption, never hard-coded. Page objects hold locators and actions, and the assertions stay in the tests.
- 08Junior
How do you mark and select tests in pytest, for example to run only the smoke tests?
Decorate tests with a mark such as @pytest.mark.smoke, then select them with pytest -m smoke, or leave them out with -m "not smoke". Register custom marks under markers in your pytest configuration, because unregistered marks raise a warning. Add --strict-markers to addopts so a misspelt mark is an error, rather than a warning while that test quietly drops out of the smoke run.
Answers checked against these official sources in November 2026:
Go Deeper on Python for Testing
Practice is free. These are the guides and project packs that turn the answers into working skills.
How does AssertHired help you practice Python questions?
Three steps. No fluff. Designed specifically for QA engineers.
Pick Your Focus
Choose from 9 QA interview types, plus a live coding challenge. 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 Python topics matter most for QA interviews?
Data structures (lists, dicts, sets), pytest (fixtures, parametrize, conftest), OOP basics, the requests library, and file handling. Understanding list comprehensions, decorators, and generators makes you stand out.
Is Python growing in test automation?
Yes. Python has become the fastest-growing language for test automation, driven by pytest's excellent design, Playwright's Python bindings, and Python's popularity in API testing and data-driven testing. Many new automation projects choose Python over Java.
pytest vs unittest, which should I learn?
pytest. It's become the de facto standard for Python testing. Its fixture system, parametrize, and plugin ecosystem are far superior to unittest. Most Python QA job postings expect pytest knowledge.
Where can I find pytest interview questions?
Start with the dedicated pytest page, linked below. It covers fixtures and scopes, parametrize, markers, conftest.py and plugins. This page covers the Python basics that sit under them: data structures, OOP and the requests library.
Can I practice Python testing interview questions on AssertHired?
Yes. AssertHired's AI interviewer covers Python in the context of test automation, pytest, API testing, page objects, and framework design patterns.
Which Python terms should you know?
Concepts interviewers expect you to define alongside Python for Testing.
How does Python compare with the alternatives?
Side-by-side comparisons of the choices this comes up against.
From the Blog
Related guides and tips to help you prepare.
More Languages for Testers Questions
Explore interview questions for related tools in this category.
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.
QA Salary Calculator
Estimate QA, SDET, and automation tester pay by level, market, and skills.
QA Offer Evaluator
See total comp, a counter range, and a ready-to-send negotiation message.
Ready for Your Python QA Interview?
Practice with AI that knows pytest, requests, and Python testing patterns.
Join 700+ QA engineers already practicing with AssertHired.
A test passes locally but fails in CI about one run in five. Walk me through what you check first, and why.
This single answer is scored on four dimensions: Technical accuracy · Coverage · Clarity · Best practices.
Rather skip ahead? Create a free account