My very simple example project contains:
addtest/
setup.py
addtest/
__init__.py
__main__.py
app.py
My app.py is just:
def main():
raise SystemExit("Command line entry point called.")
My __main__.py is just:
from addtest.app import main
main()
My setup.py contains:
from setuptools import setup, find_packages
setup(
name='AddTest',
version='1.0',
packages=find_packages(),
entry_points={
'console_scripts': ['addtest = addtest.app:main']
},
)
I would expect that running python setup.py test would do nothing, since no unit tests are written. However, running it in a clean virtualenv (Python 3.6.6 on Ubuntu 18.04.1) gives me:
$ python setup.py test
running test
running egg_info
writing AddTest.egg-info/PKG-INFO
writing dependency_links to AddTest.egg-info/dependency_links.txt
writing entry points to AddTest.egg-info/entry_points.txt
writing top-level names to AddTest.egg-info/top_level.txt
reading manifest file 'AddTest.egg-info/SOURCES.txt'
writing manifest file 'AddTest.egg-info/SOURCES.txt'
running build_ext
Command line entry point called.
Note the Command line entry point called. which means it's invoking the console script it generates from my __main__.py (or maybe just calling python -m addtest).
Why is setup.py calling the console script when I want it to run tests? Further inspection of the script's execution shows that sys.argv is ['setup.py','test'] - why?
sys.argvsys.argv[0]gives the name of the script being called, and argv provides a list of all the arguments passed to the script sopython setup.py testgives you['setup.py', 'test']. docs.python.org/3/library/sys.html#sys.argv