February 2022
Intermediate to advanced
274 pages
6h 28m
English
Most of the Cards API is accessed through a CardsDB object, but one entry point is just an attribute, cards.__version__. Let’s look at how we can use mocking to make sure the value from cards.__version__ is correctly reported through the CLI.
There are several patch methods within the mock package. We’ll be using patch.object. We’ll use it primarily in its context manager form. Here’s what it looks like to mock __version__:
| | from unittest import mock |
| | |
| | import cards |
| | import pytest |
| | from cards.cli import app |
| | from typer.testing import CliRunner |
| | |
| | runner = CliRunner() |
| | |
| | |
| | def test_mock_version(): |
| | with mock.patch.object(cards, "__version__", "1.2.3"): |
| | result = runner.invoke(app, ... |
Read now
Unlock full access