Automate tests via docstrings and more
Project description
Fastest
Creates unit tests from examples in the docstring and more
Install
$ pip install fastest
Usage
$ python main.py --path=$(pwd) --source=<source>
where path
is the the project root, and source
is same as the value passed to the command coverage run -m unittest --source=$source test
Introduction
Things that happen when you run python main.py --path=$(pwd) --source=<source>
in your
python project:
- Checks for a
test
file at the project root, it creates if it doesn't find one. - Watches
.py
files for changes. - Creates unittests if a function has examples in its docstrings like so:
# .
# ├──module_a
# ├──module_b
# └── utils.py
#
def add(x, y):
"""
example: add(3, 4) -> 7 #
"""
return x + y
This will create a unittest in the test
directory, assertEqual(add(3, 4), 7)
within Class test_<file>_<function>(self)
(for the given directory, tree: Class test_utils_add(self)
)
- Runs all tests that are created.
- Creates a coverage report (in html format).
- Print the link to the coverage reports' index.html.
How to make best use of Fastest
- Keep your
functions
light:- Be paranoid about separation of concerns.
- Too many conditions are a hint that you might need another function.
- Complex loops and
if-else
are not scalable code, a single mistake would take that tower down and feature additions would involve someone going through that brain-teaser.
- Use libraries but wrap them with your own functions. Like: Use
requests
or the inevitable database? wrap them with your own functions.- Helps with adding customizations in one place (configuring things like base url, and similar configs)
- Helps mocking so that entire code-base can be unit tested.
- Docstrings may get outdated if your work pace is fast enough to maintain quality documentation, but adding examples now would help you create tests which prevents your descriptions from going stale, either the tests fail AND the description is outdated OR else everything is fine.
Fun facts
- Fastest uses itself for its nearly automated tests and documentation.
- Excluding the files that are to be changed infrequently, Fastest has 100% code coverage.
- Fastest has 2/32 test cases failing, a testimony to its ability to find bugs.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
fastest-0.0.9.tar.gz
(11.4 kB
view hashes)
Built Distribution
fastest-0.0.9-py3-none-any.whl
(31.3 kB
view hashes)