February 2022
Intermediate to advanced
274 pages
6h 28m
English
Sometimes the application code is supposed to output something to stdout, stderr, and so on. As it happens, the Cards sample project has a command-line interface that should be tested.
The command, cards version, is supposed to output the version:
| | $ cards version |
| | 1.0.0 |
The version is also available from the API:
| | $ python -i |
| | >>> import cards |
| | >>> cards.__version__ |
| | '1.0.0' |
One way to test this would be to actually run the command with subprocess.run(), grab the output, and compare it to the version from the API:
| | import subprocess |
| | |
| | |
| | def test_version_v1(): |
| | process = subprocess.run( |
| | ["cards", "version"], capture_output=True, text=True |
| | ) |
| | output = process.stdout.rstrip() ... |
Read now
Unlock full access