I wrote a Python3 package which I am soon going to ship/share via PyPI and Github.
Now I am looking for the optimal solution for the end user to have a small test which can be run to see if after setup.py build and setup.py install the package/analysis works on the end users' system. I am NOT talking about a test on the development side.
I would ship some toy data set in order to perform the test since my package is used for data analysis.
My thoughts on this:
setup.py test would be a nice option but it seems to be deprecated soonpytest or tox firstAny recommendations on how to integrate a test into my package considering the two points above?
You can provide a __main__.py file which contains the test logic. Then the user can invoke the test via python -m your-package-name test if they wish to. For example:
# __main__.py
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('mode', choices=('test',))
args = parser.parse_args()
if args.mode == 'test':
# perform test logic here
...
Alternatively you can specify a command line script as an entry point in setup.py which allows your users to invoke your-pkg-name-test from the command line. This tutorial contains extensive information on how to realize this. Basically you need to add the following to your setup.py:
setup(
...
entry_points = {
'console_scripts': ['my-pkg-test=mypkg.user_test:main'],
}
...
)
and then ship an additional file user_test.py with the following function:
def main():
# test logic goes here
...
So the overall directory structure is as follows:
my-pkg/
├── mypkg
│ ├── __init__.py
│ ├── __main__.py # You can use either this ...
│ └── user_test.py # ... or this together with 'console_scripts'.
└── setup.py
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With