yoklainterview sim

Backend Python Testing Tooling Interview Questions

75 verified Backend Python Testing Tooling interview questions — solve with answers, learn from explanations, test yourself in a real simulation.

Try the real simulation →

Sample questions

Python Testing ToolingDifficulty 2
def test_values():
    result = [1, 2, 3]
    assert result == [1, 2, 3, 4]

What happens when this test runs?
  • aIt fails with an AssertionError, since the two lists differ in length
  • bIt raises a TypeError before comparing the lists
  • cIt passes, because both objects are lists
  • dpytest skips the test automatically because the lists differ, without ever raising an error
Explanation:== between lists compares element by element and length; [1,2,3] != [1,2,3,4], so the bare assert raises AssertionError, which pytest reports as a test failure (not an error, not a skip).
Python Testing ToolingDifficulty 1
Which function will pytest automatically discover and run as a test, in a file named test_math.py?
  • adef check_addition(): ...
  • bdef test_addition(): ...
  • cdef Addition_test(): ...
  • ddef _test_addition(): ...
Explanation:pytest's default discovery collects functions whose name starts with test_ inside files matching test_.py or _test.py. check_addition and Addition_test don't match the prefix rule, and a leading underscore also breaks discovery.
Python Testing ToolingDifficulty 2
import pytest

@pytest.fixture
def sample_data():
    return {"id": 1, "name": "alice"}

def test_name(sample_data):
    assert sample_data["name"] == "alice"

What role does sample_data play as a parameter of test_name?
  • aIt's a decorator that conditionally skips the test
  • bIt is a global variable that pytest reads automatically
  • cpytest matches the parameter name to the fixture and injects its return value
  • dIt must still be imported explicitly inside test_name for it to have any usable value at all
Explanation:pytest resolves test function parameters by name against registered fixtures. Since sample_data matches the fixture, pytest calls the fixture and passes its return value into test_name as the argument.
Python Testing ToolingDifficulty 1
import pytest

order = []

@pytest.fixture
def resource():
    order.append("setup")
    yield "R"
    order.append("teardown")

def test_use(resource):
    order.append("test")

After test_use runs, what is the value of order?
  • a["setup", "test"] — teardown never runs
  • b["setup", "teardown", "test"]
  • c["test", "setup", "teardown"]
  • d["setup", "test", "teardown"]
Explanation:Code before yield runs as setup, the value after yield is injected into the test, the test body runs, and then pytest resumes the fixture after yield to run the teardown code. So the order is setup, test, teardown.
Python Testing ToolingDifficulty 3
import pytest

@pytest.mark.parametrize("n, expected", [(2, 4), (3, 9), (4, 16)])
def test_square(n, expected):
    assert n * n == expected

How many separate test runs does pytest report for test_square?
  • aThree, one per tuple in the parametrize list
  • bTwo
  • cOne
  • dIt depends entirely on how many of the assertions inside the test body happen to fail
Explanation:@pytest.mark.parametrize generates one independent test invocation per entry in the given list, each reported separately in pytest's output. With three tuples, pytest runs and reports the test three times.
Python Testing ToolingDifficulty 2
import pytest

def divide(a, b):
    return a / b

def test_divide_by_zero():
    with pytest.raises(ZeroDivisionError):
        divide(1, 0)

What must happen inside the with pytest.raises(...) block for this test to pass?
  • aThe wrapped code must return None
  • bThe wrapped code must raise ZeroDivisionError, or a subclass of it
  • cThe wrapped code must return False
  • dThe wrapped code must print an error message to standard output before returning
Explanation:pytest.raises(ExceptionType) is a context manager that passes only if the enclosed block raises an exception matching (or subclassing) the given type; if no exception, or a different type, is raised, the test fails.

Test yourself against the 3300-question Backend bank.

Start interview