2
我已經啓動了一個小Python包(基於python-telegram-bot
),並且希望進行基於測試的開發。所以我用幾個基本的單元測試激活了py.test
。如何避免在setup.py中使用py.test提供的「No commands provided」
但我總是在setup.py
上遇到錯誤,因爲它需要命令作爲參數,但py.test
不提供任何參數。
這裏是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
)
而且py.test
結果:
=========================== 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 ========================
我明白,這是不是一個真正的錯誤setup.py
,而是與py.test
運行問題setup.py
沒有任何爭論......但我怎樣才能避免這個錯誤毀了我的測試?
你可以顯示你的代碼嗎? –
@NilsWerner:謝謝。我添加了一個簡化版本的'setup.py' –
你在你的pytest配置中設置了類似'python_files = *'的東西嗎? –