Copyright 2019 - Matt Harrison
@__mharrison__
- D - Decide
- R - Relax
- M - Motivation
- O - Observe
- M - Mechanics
Install pytest in a virtual environment
Run:
pytest -h
- Create a directory/module
Integer/integr.py(note spelling).- Create a function,
parse, that accepts a string of the form"1,3,5,9"that returns a list of integers ([1, 3, 5, 9])
- Create a function,
- Create a test directory and test file
Integer/test/test_integr.py- Create a test function,
test_basicthat asserts thatintegr.parseworks with the input"1,3,5,9"
- Create a test function,
- Run pytest on
test/test_integr.py
- Create a test function,
test_bad1that asserts that an error is raised whenintegr.parseis called with'bad input'. Use a context manager (with) - Create a test function,
test_bad2that asserts that an error is raised whenintegr.parseis called with'1-3,12-15'. Use the@pytest.mark.xfaildecorator.
- Add a
__name__check that will run pytest ontest/test_integr.pyif it is executed withpython - Run the command line option to collect the tests (but not execute them).
- Run only the
test_basictest from the command line.
- Create a doctest on the
integr.pymodule that shows an example of running theparsefunction. - Run the doctest via pytest with a command line option
- Create a
pytest.inifile. Add an option to the configuration file to run the doctests whenpytestis invoked - Run the doctest via pytest without a command line option
- Run the tests that have
badin the name - Mark
test_bad1andtest_bad2with thewrongname. - Run only tests that are marked with
wrong. - Run pytest with
--strict - Register
badas a marker inpytest.ini - Run pytest with
--strict
These questions are helpful
Thx