Try   HackMD

Pytest, Pylint and Coverage

Pytest

import pytest

This allows us to test that errors are raised and run pytest on our files.

  • This requires us to name test functions and files with '_test' or 'test_'

If you have pytest -k [insert key word here]
Pytest will search for files with that key word to run too

@pytest.mark.skip
This is a way to indicate to pytest that you want to skip over a particular test

@pytest.mark.xfail
This tells pytest that you are expecting this test to fail, so pytest will not collapse on you when you run it with this test

Pylint

Does not need import

Run with: pylint [file name].py

Just need to have this installed on your local
Run this to lint over the code
This will check that docstrings exist at the top of every function
This also checks for unused variables to make our code shorter and a little more pythonic

Coverage

Does not need import

Run with: coverage run -m pytest[test file name].py

To see report: coverage report -m

To see html: htmlcov

Just need to have this installed on your local
Run this to look at what percentage of your code your tests currently test
If you run the report or html as shown above you are able to look at what lines the test code is missing when you run pytest

This will generatecoverage html