Python for a Coding Assessment
A refresher path through the Python graph for someone who has written Python before and has an assessment coming: run and read, rebuild the core, then work the way an assessment expects.
I can write pytest tests that state what a function should do, cover the edge cases that actually break it, and fail with a message that shows what went wrong.
Writing the tests a reviewer expects to see, and reading what they say when they fail.
In scope: test functions and assert, choosing cases, parametrize, fixtures, testing that
something raises, and running the suite. Out of scope: mocking, coverage targets and continuous
integration.
assert result == 7 is a sentence: given this input, this function produces seven. A suite is the
set of claims you are prepared to defend, and the reason to have one is not correctness today but
the freedom to change the code tomorrow without reading all of it again.
pytest keeps this cheap. A file named test_*.py, functions named test_*, and a plain assert —
no class, no boilerplate. When the assert fails, pytest shows both sides of the comparison, which is
why the plain assert is enough.
Anyone can test that add(2, 2) == 4. The cases that catch bugs are the awkward ones:
pytest.raises.If a case is hard to write a test for, that is usually the function’s design talking, not the test framework’s.
@pytest.mark.parametrize runs one test body over many inputs, each reported separately, so a
failing case is named rather than hidden inside a loop. A fixture builds what several tests need
— a temporary file, a sample record — and pytest hands it to any test that asks for it by name.
Prefer tmp_path over writing into the repository.
Hand out a function with a known bug at a boundary and a suite that passes. Ask for one test that fails. Finding it is the whole skill, and it lands better than any explanation of why coverage is not the point.
For assessment practice: take any problem a learner has already solved and require tests for it before it counts as finished. That is the habit a take-home is actually grading.
| Resource | Kind | Cost | Provider |
|---|---|---|---|
| pytest: getting started | reading | free | pytest |
| pytest: how to use fixtures | reference | free | pytest |
| pytest: how to parametrize tests | reference | free | pytest |
| CS50P problem sets | practice | free | Harvard University |
A refresher path through the Python graph for someone who has written Python before and has an assessment coming: run and read, rebuild the core, then work the way an assessment expects.
A timed take-home in the shape real hiring uses: read messy data, compute a result, test it, and hand over a repository someone else can run.
The holder can take an unfamiliar problem, write a tested Python solution someone else can run, and explain what it costs.
Nothing to show yet. The publisher last published on 2026-09-20, and no aggregate for this outcome has reached the 50 learners a number needs. Open Degree does not track learners. About learner evidence.