Python 如何配置pybuilder';s和pytest';正确的道路 客观的
我想让PyBuilder使用pytest对我的python脚本进行单元测试。我和PyCharm一起工作 我试图通过,但没有成功 安装程序 我的项目结构是Python 如何配置pybuilder';s和pytest';正确的道路 客观的,python,pytest,pybuilder,Python,Pytest,Pybuilder,我想让PyBuilder使用pytest对我的python脚本进行单元测试。我和PyCharm一起工作 我试图通过,但没有成功 安装程序 我的项目结构是 <root> |- src |-main |-python |-data_merger |- gRPC |-unittest |-python 我创建了一个包含以下内容的文件/pytest.ini [pytest] py
<root>
|- src
|-main
|-python
|-data_merger
|- gRPC
|-unittest
|-python
我创建了一个包含以下内容的文件/pytest.ini
[pytest]
python_paths = src/main/python
from pybuilder.core import init, use_plugin
use_plugin("python.core")
use_plugin("python.unittest")
use_plugin("python.install_dependencies")
use_plugin("exec")
default_task = "publish"
@init
def initialize(project):
project.build_depends_on('mockito')
project.set_property("run_unit_tests_command", "py.test %s" % project.expand_path("$dir_source_unittest_python"))
project.set_property("run_unit_tests_propagate_stdout", True)
project.set_property("run_unit_tests_propagate_stderr", True)
@init
def set_properties(project):
project.set_property("dir_source_main_python", r"src/main/python/")
# project.set_property("dir_source_integrationtest_python", r"src/tests/integrationtest")
project.set_property("dir_source_unittest_python", r"src/unittest/python")
project.set_property("unittest_module_glob", "*_tests.py")
project.set_property("unittest_test_method_prefix", "test_")
project.set_property("run_unit_tests_command", "py.test %s" % project.expand_path("$dir_source_unittest_python"))
project.set_property("run_unit_tests_propagate_stdout", True)
project.set_property("run_unit_tests_propagate_stderr", True)
project.set_property("teamcity_output", True)
以及包含以下内容的文件/build.py
[pytest]
python_paths = src/main/python
from pybuilder.core import init, use_plugin
use_plugin("python.core")
use_plugin("python.unittest")
use_plugin("python.install_dependencies")
use_plugin("exec")
default_task = "publish"
@init
def initialize(project):
project.build_depends_on('mockito')
project.set_property("run_unit_tests_command", "py.test %s" % project.expand_path("$dir_source_unittest_python"))
project.set_property("run_unit_tests_propagate_stdout", True)
project.set_property("run_unit_tests_propagate_stderr", True)
@init
def set_properties(project):
project.set_property("dir_source_main_python", r"src/main/python/")
# project.set_property("dir_source_integrationtest_python", r"src/tests/integrationtest")
project.set_property("dir_source_unittest_python", r"src/unittest/python")
project.set_property("unittest_module_glob", "*_tests.py")
project.set_property("unittest_test_method_prefix", "test_")
project.set_property("run_unit_tests_command", "py.test %s" % project.expand_path("$dir_source_unittest_python"))
project.set_property("run_unit_tests_propagate_stdout", True)
project.set_property("run_unit_tests_propagate_stderr", True)
project.set_property("teamcity_output", True)
错误
当我运行pyb
或pyb run\u unit\u测试
相应的命令时,会出现以下错误:
PyBuilder version 0.10.36
Build started at 2017-06-09 12:33:28
------------------------------------------------------------
[INFO] Building myproject version 1.0-SNAPSHOT
[INFO] Executing build in ~/myproject
[INFO] Going to execute task publish
[INFO] Executing unittest Python modules in ~/myproject/src/unittest/python
[INFO] Executed 2 unittests
[ERROR] Test has error: unittest.loader._FailedTest.children_statistics_tests
[ERROR] Test has error: unittest.loader._FailedTest.clusterEvents_tests
##teamcity[testStarted name='children_statistics_tests (unittest.loader._FailedTest)']
##teamcity[testFailed name='children_statistics_tests (unittest.loader._FailedTest)' message='See details' details='<class ImportError>: Failed to import test module: children_statistics_tests
Traceback (most recent call last):
File "~/anaconda2/envs/myenv/lib/python3.6/unittest/loader.py", line 153, in loadTestsFromName
module = __import__(module_name)
File "~/myproject/src/unittest/python/children_statistics_tests.py", line 5, in <module>
import src.main.python.gRPC.event_clustering_module as ec
ModuleNotFoundError: No module named src
']
##teamcity[testFinished name='children_statistics_tests (unittest.loader._FailedTest)']
##teamcity[testStarted name='clusterEvents_tests (unittest.loader._FailedTest)']
##teamcity[testFailed name='clusterEvents_tests (unittest.loader._FailedTest)' message='See details' details='<class ImportError>: Failed to import test module: clusterEvents_tests
Traceback (most recent call last):
File "~/anaconda2/envs/myenv/lib/python3.6/unittest/loader.py", line 153, in loadTestsFromName
module = __import__(module_name)
File "~/myproject/src/unittest/python/clusterEvents_tests.py", line 3, in <module>
import src.main.python.gRPC.event_clustering_module as ec
ModuleNotFoundError: No module named src
']
##teamcity[testFinished name='clusterEvents_tests (unittest.loader._FailedTest)']
------------------------------------------------------------
BUILD FAILED - There were 2 test error(s) and 0 failure(s)
------------------------------------------------------------
Build finished at 2017-06-09 12:33:28
Build took 0 seconds (832 ms)
到
但结果是
$ pytest
========================================================================================== test session starts ===========================================================================================
platform linux -- Python 3.6.1, pytest-3.1.1, py-1.4.33, pluggy-0.4.0
rootdir: ~/myproject, inifile: pytest.ini
plugins: pythonpath-0.7.1
collected 0 items
====================================================================================== no tests ran in 0.02 seconds ======================================================================================
然后我将pytest.ini
更改为
[pytest]
python_paths = src/unittest/python
但这并没有改变任何事情。运行pyb
或pyb运行单元测试
会导致
[INFO] Executing unittest Python modules in ~/myproject/src/unittest/python
[WARN] No unittests executed.
[INFO] All unittests passed.
问题:
显然,有关路径的某些设置不起作用。我错过了什么,我需要做什么
[INFO] Executing unittest Python modules in ~/myproject/src/unittest/python
[WARN] No unittests executed.
[INFO] All unittests passed.