Pytest-console-scripts is a pytest plugin for running python scripts from within tests. It's quite similar to subprocess.run(), but it also has an in-process mode, where the scripts are executed by the interpreter that's running pytest (using some amount of sandboxing).