Skip to content

Instantly share code, notes, and snippets.

@sailik1991
Last active May 23, 2020 23:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sailik1991/ff68243398c7fc3e05bc551df3118a8d to your computer and use it in GitHub Desktop.
Save sailik1991/ff68243398c7fc3e05bc551df3118a8d to your computer and use it in GitHub Desktop.

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment