pytest-json-report 项目教程
1. 项目的目录结构及介绍
pytest-json-report/
├── github/
│ └── workflows/
├── tests/
├── .coveragerc
├── .gitignore
├── LICENSE
├── README.md
├── sample_report.json
├── setup.py
└── tox.ini
目录结构介绍
- github/workflows/: 包含GitHub Actions的工作流配置文件。
- tests/: 包含项目的测试文件。
- .coveragerc: 代码覆盖率配置文件。
- .gitignore: Git忽略文件配置。
- LICENSE: 项目的开源许可证文件。
- README.md: 项目的介绍和使用说明。
- sample_report.json: 示例的JSON报告文件。
- setup.py: 项目的安装配置文件。
- tox.ini: Tox配置文件,用于自动化测试。
2. 项目的启动文件介绍
setup.py
setup.py
是Python项目的标准安装文件,用于定义项目的元数据和依赖项。通过运行 python setup.py install
可以安装该项目。
from setuptools import setup, find_packages
setup(
name='pytest-json-report',
version='1.0.0',
description='A pytest plugin to report test results as JSON',
long_description=open('README.md').read(),
long_description_content_type='text/markdown',
author='numirias',
author_email='numirias@example.com',
url='https://github.com/numirias/pytest-json-report',
packages=find_packages(),
install_requires=[
'pytest>=3.5.0',
],
entry_points={
'pytest11': [
'json-report = pytest_jsonreport.plugin',
],
},
classifiers=[
'Framework :: Pytest',
'License :: OSI Approved :: MIT License',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
],
)
3. 项目的配置文件介绍
.coveragerc
.coveragerc
文件用于配置代码覆盖率工具 coverage.py
。
[run]
omit =
*/tests/*
*/setup.py
[report]
exclude_lines =
pragma: no cover
def __repr__
if self.debug
if __name__ == .__main__.:
tox.ini
tox.ini
文件用于配置 tox
,一个用于自动化测试的工具。
[tox]
envlist = py36,py37,py38,py39
[testenv]
deps =
pytest
pytest-cov
commands =
pytest --cov=pytest_jsonreport --cov-report=term-missing
通过这些配置文件,可以确保项目在不同的Python版本下进行测试,并且生成代码覆盖率报告。