Skip to content
Learn Netverks

Lesson

Step 32/36 89% through track

testing-pytest

Testing with pytest

Last reviewed May 28, 2026 Content v20260528
Track mode
server_script
Means
Server runner
Reading
~1 min
Level
intermediate

This lesson

This lesson teaches Testing with pytest: the syntax, patterns, and safety habits you need before advancing in Python.

Teams still ship Testing with pytest in Python codebases—skipping it leaves gaps in debugging and code reviews.

You will apply Testing with pytest in contexts like: CI test suites for libraries, data jobs, and internal tools.

Write Python 3 in the editor and click Run on server—the dev runner executes your script with print() for output; stdlib only in playground snippets (LEARNING_RUNNER_ENABLED=true).

Toward the end of the track—consolidate before capstone-style review lessons.

pytest is the dominant Python test runner—install locally with pip. Tests are plain functions named test_* with assert statements—simpler than Java JUnit boilerplate for many teams.

Example test (local)

# test_math.py
def add(a, b):
    return a + b

def test_add():
    assert add(2, 3) == 5
pip install pytest
pytest -q

Simulating tests in playground

The sandbox cannot run pytest CLI—assert in functions to practice Arrange-Act-Assert thinking before local pytest setup.

Important interview questions and answers

  1. Q: pytest vs unittest?
    A: unittest is stdlib xUnit style; pytest has simpler asserts and rich plugin ecosystem.
  2. Q: Arrange-Act-Assert?
    A: Setup data, invoke behavior, verify outcome—readable test structure.

Self-check

  1. What prefix names a pytest test function?
  2. What CLI runs pytest locally?

Tip: Name tests test_feature_scenario_expected—run pytest -q locally after pip install pytest.

Interview prep

pytest vs unittest?

unittest stdlib xUnit style; pytest simpler asserts and plugin ecosystem—both valid.

Arrange-Act-Assert?

Setup, invoke, assert—readable structure for maintainable tests.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs on the configured server runner (dev: npm run runner with LEARNING_RUNNER_ENABLED=true). Output appears below the editor.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • fixture scope?
  • parametrize?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump