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_basic
that asserts thatintegr.parse
works with the input"1,3,5,9"
- Create a test function,
- Run pytest on
test/test_integr.py
- Create a test function,
test_bad1
that asserts that an error is raised whenintegr.parse
is called with'bad input'
. Use a context manager (with
) - Create a test function,
test_bad2
that asserts that an error is raised whenintegr.parse
is called with'1-3,12-15'
. Use the@pytest.mark.xfail
decorator.
- Add a
__name__
check that will run pytest ontest/test_integr.py
if it is executed withpython
- Run the command line option to collect the tests (but not execute them).
- Run only the
test_basic
test from the command line.
- Create a doctest on the
integr.py
module that shows an example of running theparse
function. - Run the doctest via pytest with a command line option
- Create a
pytest.ini
file. Add an option to the configuration file to run the doctests whenpytest
is invoked - Run the doctest via pytest without a command line option
- Run the tests that have
bad
in the name - Mark
test_bad1
andtest_bad2
with thewrong
name. - Run only tests that are marked with
wrong
. - Run pytest with
--strict
- Register
bad
as a marker inpytest.ini
- Run pytest with
--strict
These questions are helpful
Thx