Check console script with Pytest
Pytest is the de facto standard for Python unit testing and continuous integration. To be complete in testing, one should test the interactive console scripts that for many Python programs is the main method of use.
Console script testing can be added through
Pytest Console Scripts
addon, but I usually simply use subprocess.check_call
directly like Pytest Console Scripts addon does.
Example
From the
findssh
package tests/test_scripts.py
:
#!/usr/bin/env python
import pytest
import subprocess
def test_find():
subprocess.check_call(['findssh'])
Did not include the .py
suffix because
setup.cfg
includes:
[options.entry_points]
console_scripts =
findssh = findssh:main
which is useful for cross-platform command line use. The user just types into Terminal or Command Prompt:
findssh
to run the Python program.