创建具有以下文件夹结构的项目目录后:
src/snnalgorithms__main__.py
tests/some_test.py
tests/some_dir/other_test.py
并将其发布为 pip 包,我收到错误:
from snnalgorithms.tests.sparse.MDSA.test_snn_results import Test_mdsa_snn_results
E ModuleNotFoundError: No module named 'snnalgorithms.tests'
当我尝试从另一个 pip 包/python 代码/项目调用该测试文件时。我会预料到这个错误,因为我没有告诉
setup.py
(有内容)和setup.cfg
pip
包应该包含tests
目录。
"""Packaging logic for snnalgorithms."""
from __future__ import annotations
import os
import sys
import setuptools
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "src"))
# sys.path.insert(1, os.path.join(os.path.dirname(__file__), "tests"))
install_requires = [
"lava @ https://github.com/a-t-0/lava/archive/refs/tags/v0.5.1.tar.gz",
]
setuptools.setup()
[metadata]
name = snnalgorithms
version = attr: snnalgorithms.__version__
description = compares snn algorithms against neumann algorithms
long_description = file: README.md
long_description_content_type = text/markdown
url = https://github.com/a-t-0/snnalgorithms
author = a-t-0
author_email = [email protected]
maintainer = a-t-0
maintainer_email = [email protected]
license = AGPLv3
license_file = licence
classifiers =
Development Status :: 2 - Pre-Alpha
Environment :: Console
Intended Audience :: Science/Research
License :: OSI Approved :: GNU Affero General Public License v3
Programming Language :: Python
Programming Language :: Python :: 3
Programming Language :: Python :: 3 :: Only
Programming Language :: Python :: 3.10
Topic :: Scientific/Engineering :: Artificial Intelligence
[options]
packages = find:
package_dir =
=src
# Dependencies
install_requires =
jsons>=1.6.3
matplotlib>=3.6.1
networkx>=2.8.7
numpy>=1.23.4
pyannotate>=1.2.0
pytest-cov>=4.0.0
typeguard>=2.13.3
python_requires = >=3.10
[options.packages.find]
where = src
[options.entry_points]
console_scripts =
snnalgorithms = snnalgorithms:main
[bdist_wheel]
universal = 1
[mypy]
check_untyped_defs = true
disallow_any_generics = true
disallow_incomplete_defs = true
disallow_untyped_defs = true
no_implicit_optional = true
warn_unused_ignores = true
[mypy-tests.*]
disallow_untyped_defs = false
根据评论,我了解到将测试包含在用户安装的 pip 包中是不可取的/常规的。相反,我们可以区分 pip 的
wheel
和 sdist
分布。我相信 wheel
包含用户的 MWE pip 包,而 sdist
也可能包括测试。
如何将存储库根目录中的测试包含到 pip 包中,以便其他 pip 包能够使用/导入这些测试?