首先需要安装 wheel, setuptools
pip install setuptools wheel
简单进行一个打包的例子,项目目录结构如下:
# __init__.py
def pytest_collection_modifyitems(session, config, items):for item in items:# item.name 用例名称item.name = item.name.encode('utf-8').decode('unicode-escape')# item.nodeid 用例路径item._nodeid = item.nodeid.encode('utf-8').decode('unicode-escape')
创建 setup.py 文件:
from setuptools import setupsetup(name='testWhl',url='https://github.com/xxx/testWhl',version='1.0',author="xixi",author_email='418974188@qq.com',packages=['test'],description='set your encoding and logger',long_description='Show Chinese for your mark.parametrize(). Define logger variable for getting your log',classifiers=[# 分类索引 ,pip 对所属包的分类'Framework :: Pytest','Programming Language :: Python','Topic :: Software Development :: Testing','Programming Language :: Python :: 3.11.9',],license='proprietary',keywords=['pytest', 'py.test', 'pytest_encode',],# 需要安装的依赖install_requires=['pytest'],# 入口模块 或者入口函数entry_points={'pytest11': ['pytest-encode = pytest_encode',]},zip_safe=False
)
进入项目与 setup.py 同级目录进行打包:
python setup.py sdist bdist_wheel
上面是源码包,下面的是 whl 包,可以通过 pip install 进行安装
pip install testWhl-1.0-py3-none-any.whl
发布到PyPI: