Simplest Pytest Setup

This is the most basic project layout for running pytest, a desirable test runner for your python code.

Prerequisites

First, get python3 installed. Then a virtual environment, like pipenv.

Get dependencies

Then use pipenv to get your pytest dependencies.

cd my_project
pipenv shell
pipenv install pytest pytest-watch

Create project files

Then create your source file, vim module.py:

def placeholder():
    return True

Then create your test file, vim module_test.py:

from module import placeholder

def test_placeholder():
    assert placeholder()

Ensure the import will work by making the directory a package: touch __init__.py.

Run the tests

Now you should be ready to run tests.

pytest will run the tests once.

ptw will run the tests in watch mode.

That's the simplest pytest setup I could conceive. Can you think of a simpler one? Of a better one?