This repository shows a basic setup for a command line application in Python.
Python and Pipenv is expected to be installed on our system.
After cloning this repository, change into the newly created directory and run
pipenv install --dev
This will install all dependencies needed for the project.
All tests can be run by executing
pipenv run test
test
will invoke pytest
which will then find all tests inside the tests
directory and run them.
The test for class Example
is only verifying the return value of one method.
Main
on the other hand is tested via a test-double that gets injected.
This allows us to spy on the output of it.
We want to avoid printing anything to the screen while running the tests.
Injecting a test double in this instance is a nice way to isolate our application from the command line.
At the bottom of the executable main module sample/main.py
we inject sys.stdout
, which is Python's variable for its standard output.
To run the application execute the main module sample.main
.
You should see the text “Python Example” being printed.
$: python -m sample.main
Python Example
This project is licensed under the MIT License - see the license.md file for details.