- Go to your project folder
cd my-projectUse your own folder name.
- Create a virtual environment
python3 -m venv .venvSkip this if your project already has one.
- Switch it on
source .venv/bin/activateYour prompt now starts with (.venv).
- Install pytest
pip install pytest - Run all your tests
pytestpytest finds files named test_*.py or *_test.py and runs every function whose name starts with test.
- Run the tests in one file
pytest tests/test_login.py - Run only tests whose name matches
pytest -k "test_login"The -k option picks tests by name. Any test with that text in its name runs.
- Stop at the first failure
pytest -xHandy when many tests fail for the same reason.
- Show each test's name and result
pytest -vYou can mix options, for example pytest -x -v {{file}}.
Check it worked
- Check pytest is installed in the environment
pytest --version
Undo it
- Remove pytest
pip uninstall -y pytest - Switch the environment off
deactivate
- Go to your project folder
cd my-projectUse your own folder name.
- Create a virtual environment
python3 -m venv .venvSkip this if your project already has one. On Debian and Ubuntu you may need sudo apt install python3-venv first.
- Switch it on
source .venv/bin/activateYour prompt now starts with (.venv).
- Install pytest
pip install pytest - Run all your tests
pytestpytest finds files named test_*.py or *_test.py and runs every function whose name starts with test.
- Run the tests in one file
pytest tests/test_login.py - Run only tests whose name matches
pytest -k "test_login"The -k option picks tests by name. Any test with that text in its name runs.
- Stop at the first failure
pytest -xHandy when many tests fail for the same reason.
- Show each test's name and result
pytest -vYou can mix options, for example pytest -x -v {{file}}.
Check it worked
- Check pytest is installed in the environment
pytest --version
Undo it
- Remove pytest
pip uninstall -y pytest - Switch the environment off
deactivate
- Go to your project folder
cd my-projectUse your own folder name.
- Create a virtual environment
py -m venv .venvSkip this if your project already has one.
- Switch it on
.venv\Scripts\Activate.ps1Your prompt now starts with (.venv). If PowerShell says scripts are disabled, see the virtual environment page.
- Install pytest
pip install pytest - Run all your tests
pytestpytest finds files named test_*.py or *_test.py and runs every function whose name starts with test.
- Run the tests in one file
pytest tests/test_login.pyForward slashes work fine in the path on Windows too.
- Run only tests whose name matches
pytest -k "test_login"The -k option picks tests by name. Any test with that text in its name runs.
- Stop at the first failure
pytest -xHandy when many tests fail for the same reason.
- Show each test's name and result
pytest -vYou can mix options, for example pytest -x -v {{file}}.
Check it worked
- Check pytest is installed in the environment
pytest --version
Undo it
- Remove pytest
pip uninstall -y pytest - Switch the environment off
deactivate