Testing Fundamentals with Pytest
This course teaches professional software testing in Python using pytest, building a complete test suite for an expense-tracking application from scratch. It covers test discovery, assertion rewriting, fixtures with scope control, parametrize for data-driven tests, mocking with monkeypatch and unittest.mock, testing exceptions, custom markers, and coverage reporting — the complete toolkit for writing reliable, maintainable tests in real-world Python projects.
Совместимая лаборатория
VSCode Cloud Sandbox
The VSCode Cloud IDE sandbox offers a wide range of core technologies used in programming such Python pytest, GIT, python poetry, Cerberus and many more....
10,0 (2)Главы
10Testing Python Code: Getting Started with pytest
This chapter introduces pytest — how it discovers tests, how to run them, and how to write the first meaningful test functions for a real Python application. It sets up the expense-tracker project that the rest of the course builds on.
Structuring Assertions and Test Cases in pytest
This chapter covers how to write precise, informative assertions using pytest's assertion rewriting system, when to use single versus multiple assertions per test, how to compare complex objects, and how to group related tests in classes for shared organization.
Reusable Test Setup with pytest Fixtures
This chapter introduces pytest fixtures — the mechanism for creating reusable test setup code. It covers defining fixtures, controlling their scope (function, class, module, session), sharing fixtures across files with conftest.py, and composing fixtures from other fixtures.
Data-Driven Testing with pytest.mark.parametrize
This chapter covers pytest.mark.parametrize for writing data-driven tests — running the same test logic against multiple input-output pairs without duplicating test code. It includes parametrize with IDs, multiple parameters, and combining parametrize with fixtures.
Isolating Dependencies with Mocking in pytest
This chapter covers isolating test targets from external dependencies using pytest's monkeypatch fixture and Python's unittest.mock library. It demonstrates patching functions, modules, and objects to make tests fast, deterministic, and independent of network calls or file I/O.
Testing Error Conditions and Exceptions in pytest
This chapter covers how to test that code raises the right exceptions under the right conditions using pytest.raises, how to inspect exception messages and types, and how to use pytest.warns for testing warnings — the complete toolkit for verifying error-handling behavior.
Organizing and Filtering Tests with pytest Markers
This chapter covers pytest markers for categorizing and controlling test execution — built-in markers like skip, skipif, and xfail; custom markers for grouping tests; and the -k and -m flags for running targeted subsets of the test suite.
Test Coverage and Project Structure in pytest
This chapter covers professional test suite organization — structuring a tests/ directory, using conftest.py at different levels of the project hierarchy, configuring pytest with pytest.ini or pyproject.toml, and measuring code coverage with pytest-cov.
Course Summary
A comprehensive recap of every concept covered in the course — from test discovery and assertion rewriting through fixtures, parametrize, mocking, exception testing, markers, and coverage — synthesizing the complete pytest toolkit into a coherent testing strategy.
Pytest Final Assessment
The final assessment for the pytest course — ten multiple-choice questions covering test discovery, assertion rewriting, fixture scope, parametrize, mocking, pytest.raises, markers, and coverage reporting.
Комментарии