← All Python MCQ topics and your readiness dashboard
Test your Testing with pytest knowledge with a timed Python MCQ mock test for interviews. Each attempt gives you 20 random questions in 20 minutes from a 200-question bank covering test discovery and naming, plain assert and assertion rewriting, fixtures and scopes, yield teardown, conftest.py, parametrize and ids, markers with -m and -k, skip, skipif and xfail, pytest.raises and approx, tmp_path, monkeypatch, capsys and caplog, mocks and patching, command-line options and ini settings, plugins such as xdist, html and pytest-playwright, and flaky-test practice; 81 questions run a real pytest session. 180 questions are written from a QA and test-automation angle and the rest from a developer angle; your result shows both scores.
What this Python MCQ test covers
Revise these lessons from the free Python tutorial before or after your test:
Sample Python pytest questions with answers
- Q. pytest_run(src) saves src as a test file, runs pytest -q and returns the summary line. What does this code print?
print(pytest_run("""
def test_add():
assert 1 + 1 == 2
def test_sub():
assert 3 - 1 == 1
"""))
Answer:1 failed, 1 passed
Each test function is collected; the second assertion is false. - Q. pytest_run(src) saves src as a test file, runs pytest -q and returns the summary line. What does this code print?
print(pytest_run("""
def helper():
assert False
def test_ok():
assert True
"""))
Answer:1 passed
Only functions named test_* are collected; helper is never run. - Q. pytest_run(src) saves src as a test file, runs pytest -q and returns the summary line. What does this code print?
print(pytest_run("""
class TestCart:
def test_empty(self):
assert [] == []
def test_total(self):
assert sum([1, 2]) == 3
"""))
Answer:2 passed
Methods named test_* inside Test* classes are collected. - Q. What does this code print?
import pytest
print(0.1 + 0.2 == pytest.approx(0.3), 100 == pytest.approx(101, rel=0.05), 1 == pytest.approx(2))
Answer:True True False
approx uses a relative tolerance of 1e-6 by default; rel=0.05 allows 5%. - Q. What does this code print?
import pytest
print([0.1 + 0.2, 1.0] == pytest.approx([0.3, 1.0]), {"a": 0.30000001} == pytest.approx({"a": 0.3}))
Answer:True True
approx also works on lists and dicts of numbers. - Q. What does this code print?
import pytest
with pytest.raises(KeyError) as exc_info:
{}["sku"]
print(exc_info.type.__name__, exc_info.value.args[0])
Answer:KeyError sku
exc_info gives access to the raised exception for further checks.
Every predict-the-output question in this bank was run on Python 3, so the answer is the real output. Go back to the Python MCQ dashboard to see your overall Python learning progress and interview readiness.
Frequently asked questions
How many questions does the Python pytest MCQ test have?
The bank has 200 questions. Each test picks 20 at random, favouring questions you have not seen yet, so about 10 attempts cover the whole bank.
How long is each test and what is the pass mark?
Each test has a 20-minute timer and submits itself when time runs out. You pass with 70%, which is 14 of 20 correct.
Is this test useful for QA and automation engineer interviews?
Yes. 180 of the questions use test-automation scenarios such as parsing UI text, test data and assertions, and your result shows your QA score separately.
Can I retake the test?
Yes, as often as you like. Every retake draws a fresh set of 20 questions and counts toward your 20-test readiness target.