A quick guide to setup pytest for your python code. Convert your code into a package by using the following directory structure.
setup.py
src
-- /a/1.py
tests
-- test_a_1.py
The setup.py
file is configured as follows:
#!/usr/bin/env python
from setuptools import setup, find_packages
setup(
# Creates packages to import 1.py and 2.py into test files
packages=find_packages("src", exclude=["tests*"]),
package_dir={"": "src"},
# Sets up tests
setup_requires=["pytest-runner"],
tests_require=["pytest"],
test_suite="tests.test_a_1",
# Metadata
name="Repo Name",
author="Your Name",
author_email="your@email.com",
include_package_data=True,
license="TBD"
)
The tests can be run using:
python setup.py develop
python setup.py test