I have started a small Python package (based on python-telegram-bot
) and want to do test-based development. So I activated py.test
with a few basic unit tests.
But I always get an error on setup.py
because it requires a command as argument, but py.test
doesn't provide any.
Here is a shortened version of setup.py
:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from setuptools import setup
requirements = [
'python-telegram-bot>=5.3.0'
]
test_requirements = [
'pytest>=3.0'
]
setup(
name='project',
version='0.1.0',
packages=[
'project',
],
package_dir={'project':
'project'},
entry_points={
'console_scripts': [
'project=project.cli:main'
]
},
include_package_data=True,
install_requires=requirements,
license="MIT license",
zip_safe=False,
test_suite='tests',
tests_require=test_requirements
)
And the py.test
results:
=========================== test session starts ==========================
platform darwin -- Python 3.6.0, pytest-3.0.6, py-1.4.32, pluggy-0.4.0
rootdir: ~/dev/project, inifile: pytest.ini
collected 4 items / 1 errors
================================= ERRORS =================================
________________________ ERROR collecting setup.py _______________________
/usr/local/Cellar/python3/3.6.0_1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/distutils/core.py:134: in setup
ok = dist.parse_command_line()
../../../.virtualenvs/project/lib/python3.6/site-packages/setuptools/dist.py:358: in parse_command_line
result = _Distribution.parse_command_line(self)
/usr/local/Cellar/python3/3.6.0_1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/distutils/dist.py:490: in parse_command_line
raise DistutilsArgError("no commands supplied")
E distutils.errors.DistutilsArgError: no commands supplied
During handling of the above exception, another exception occurred:
setup.py:58: in <module>
tests_require=test_requirements
/usr/local/Cellar/python3/3.6.0_1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/distutils/core.py:136: in setup
raise SystemExit(gen_usage(dist.script_name) + "\nerror: %s" % msg)
E SystemExit: usage: py.test [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
E or: py.test --help [cmd1 cmd2 ...]
E or: py.test --help-commands
E or: py.test cmd --help
E
E error: no commands supplied
!!!!!!!!!!!!!!!!! Interrupted: 1 errors during collection !!!!!!!!!!!!!!!!
========================= 1 error in 1.04 seconds ========================
I understand that it is not really an error in setup.py
, but rather a problem with py.test
running setup.py
without any argument... But how can I avoid this error ruining my testing?
If you really want isolation instead just doing python setup.py install in virtualenv. Then use virtualbox and install some free linux os in it. Take a snapshot of the machine after the install so you can revert easily with one click to the starting point at any time and try python setup.py install there.
py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools. I found a very detailed write-up explaining this issue: "Why you shouldn't invoke setup.py directly" (October 2021).
The setup.py file may be the most significant file that should be placed at the root of the Python project directory. It primarily serves two purposes: It includes choices and metadata about the program, such as the package name, version, author, license, minimal dependencies, entry points, data files, and so on.
Add conftest.py
file to the root dir with the following text:
collect_ignore = ['setup.py']
It will tell py.test to ignore 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