Exercises
Now that you have seen several testing and logging options, it’s time to try it yourself.
A few challenges:
- Create a function that tests the doctests of a given function/class.
- For a greater challenge, create a function that recursively tests all doctests of every function and class in a given module.
- Create a
py.test
plugin that checks if all tested files have file-level documentation. Hint: usepytest_collect_file
. - Create a custom
tox
environment to runflake8
ormypy
on your project. - Create a
LoggerAdapter
that combines multiple messages into a single message based on some task ID. This can be useful when debugging long-running tasks.
Example answers for these exercises can be found on GitHub: https://github.com/mastering-python/exercises. You are encouraged to submit your own solutions and learn about alternative solutions from others.