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.


From the findssh package tests/

#!/usr/bin/env python
import pytest
import subprocess

def test_find():

Did not include the .py suffix because setup.cfg includes:

console_scripts =
  findssh = findssh:main

which is useful for cross-platform command line use. The user just types into Terminal or Command Prompt:


to run the Python program.