这是我的build.py:
import os
import shutil
import subprocess
from pybuilder.core import use_plugin, init, task, Author
use_plugin('python.core')
use_plugin('python.unittest')
use_plugin('python.coverage')
use_plugin('python.distutils')
use_plugin('python.install_dependencies')
use_plugin('pypi:elasticsearch')
authors = [Author('eagle', 'email')]
version = '1.0'
description = 'Pipeline thing test'
requires_python = '>=3.0'
default_task = ['install_dependencies', 'publish', 'setup', 'analyze']
@init
def initialize(project):
project.build_depends_on('elasticsearch')
project.set_property('dir_source_unittest_python','tests')
project.set_property('dir_source_main_python','src')
project.set_property('unittest_module_glob','test_*')
project.set_property('coverage_branch_partial_threshold_warn ',80)
project.set_property('coverage_threshold_warn',80)
project.set_property('coverage_break_build',False)
project.set_property('distutils_use_setuptools',True)
project.set_property('distutils_classifiers',['Development Status :: 3 - Alpha', 'Intended Audience :: Developers', 'Topic :: Software Development :: Pipeline', 'License :: OSI Approved :: MIT License', 'Programming Language :: Python :: 3.6'])
@task
def setup():
subprocess.check_output(['python3.6','target/dist/pythonutilities-1.0/setup.py', 'install'])
它专门在projectDir / tests下寻找测试目录 在project.set_property中指定(' dir_source_unittest_python',' tests') 它看起来确实找到了正确的测试文件:
File "/Users/adc1blz/Desktop/Work/pythonutilities/tests/test_elastic_controller.py", line 4, in <module>
但我仍然收到以下错误:
ImportError: Failed to import test module: test_elastic_controller
Traceback (most recent call last):
File "/usr/local/Cellar/python3/3.6.4_2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/unittest/loader.py", line 153, in loadTestsFromName
module = __import__(module_name)
File "/Users/adc1blz/Desktop/Work/pythonutilities/tests/test_elastic_controller.py", line 4, in <module>
from src.elastic_controller import ElasticController
ModuleNotFoundError: No module named 'src'
我通过删除
尝试使用默认项目结构project.set_property('dir_source_unittest_python','tests')
project.set_property('dir_source_main_python','src')
然后移动我的测试和src目录,但我仍然得到相同的错误。我正在运行的具体命令是:
> python3.6 -m virtualenv env
> source env/bin/activate
> pip3.6 install pybuilder
> pyb -X
为什么PyBuilder在虚拟环境中找不到src模块?拜托,这真令人沮丧。
克里斯