python - python setup.py test 使用 pytest 时无法进行精细测试
问题描述
我的项目目录如下所示
setup.py
chtools/
__init__.py
perspective-tool
lib/
tests/
__init__.py
setup.cfg
test_perspective.py
当我从我的项目目录(即与 setup.py 相同的级别)运行 pytest 时,一切都按预期工作。
(.venv) desktop:cloudhealth-tools$ pytest
platform linux -- Python 3.6.3, pytest-3.6.3, py-1.5.4, pluggy-0.6.0
rootdir: /home/jjk3/PycharmProjects/cloudhealth-tools, inifile:
collected 3 items
chtools/tests/test_perspective.py ... [100%]
但是当我运行python setup test
它时无法找到测试。
(.venv) desktop:cloudhealth-tools$ python setup.py test
running test
running egg_info
writing chtools.egg-info/PKG-INFO
writing dependency_links to chtools.egg-info/dependency_links.txt
writing entry points to chtools.egg-info/entry_points.txt
writing requirements to chtools.egg-info/requires.txt
writing top-level names to chtools.egg-info/top_level.txt
reading manifest file 'chtools.egg-info/SOURCES.txt'
writing manifest file 'chtools.egg-info/SOURCES.txt'
running build_ext
----------------------------------------------------------------------
Ran 0 tests in 0.000s
OK
我添加setup_requires
并tests_require
如 pytest 文档中所述,https: //docs.pytest.org/en/2.9.1/goodpractices.html ,但没有运气。
setup.py
如下:
from setuptools import setup, find_packages
with open('README.md') as readme_file:
readme = readme_file.read()
setup(name='chtools',
version='1.0.6',
description='Automation Tools for CloudHealth',
url='https://github.com/bluechiptek/cloudhealth-tools',
author='BlueChipTek',
author_email='joe@bluechiptek.com',
long_description_content_type='text/markdown',
long_description=readme,
license='GPLv3',
packages=find_packages(),
python_requires='>=3',
install_requires=[
'certifi==2018.1.18',
'chardet==3.0.4',
'idna==2.6',
'PyYAML==3.13',
'requests==2.18.4',
'urllib3==1.22'
],
setup_requires=['pytest-runner'],
tests_require=['pytest'],
entry_points={
'console_scripts': ['perspective-tool=chtools.perspective_tool:main']
},
classifiers=[
'License :: OSI Approved :: GNU General Public License v3 (GPLv3)',
'Programming Language :: Python :: 3 :: Only'
]
)
提前感谢您的帮助!
解决方案
您setup.cfg
驻留在错误的目录中:它必须与setup.py
:
chtools/
__init__.py
lib/
perspective-tool
tests/
__init__.py
test_perspective.py
setup.cfg
setup.py
你应该声明一个别名test
:setup.cfg
[aliases]
test=pytest
推荐阅读
- unit-testing - 有没有办法用 Mockito 在 Dart 中仅模拟对象的一部分?
- node.js - 错误:ENOENT:没有这样的文件或目录,打开“dist/index.html”
- java - 使用 Apache Arrow 读取 Parquet 文件
- bash - 如何使用 sed 删除从 pattern_1 到第二次出现 pattern_2 的行?
- php - 无法使用 xampp 在本地主机上使用自定义域
- ionic-framework - Ionic 4 App 上传到应用商店并出现警告
- html - 从多个表单中读取通过单个按钮提交的烧瓶中的多个文件
- visual-studio-2019 - 如何从 Visual Studio 运行 Tizen 证书管理器
- sas - 如何在 SAS 中输入带有数字名称的变量?
- flask - 使用烧瓶在网页上显示存储在 s3 中的图像