3

Here's my 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'])

It's specifically looking for the test directory under projectDir/tests as specified in project.set_property('dir_source_unittest_python','tests') And it does look there and find the correct test file:

  File "/Users/adc1blz/Desktop/Work/pythonutilities/tests/test_elastic_controller.py", line 4, in <module>

But I still receive the following error:

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'

I've tried using the default project structure by deleting

project.set_property('dir_source_unittest_python','tests')
project.set_property('dir_source_main_python','src')

and then moving around my test and src directory, but still I get the same error. The specific commands that I'm running that cause this are:

> python3.6 -m virtualenv env
> source env/bin/activate 
> pip3.6 install pybuilder
> pyb -X

Why can't PyBuilder find the src module while in a virtual environment? Please, this is has been so frustrating.

Chris

CrizR
  • 688
  • 1
  • 6
  • 26
  • Still no solution to this, but I ended up not using PyBuilder and instead created a script to install dependencies and run tests for the pipeline. I encountered almost no problems. Something with PyBuilder was causing quite a lot of issues. – CrizR Mar 01 '18 at 04:22
  • I am facing the same issue on Windows and Python 3.7 (even if my original problem was different). I opened an issue on [pybuilder github](https://github.com/pybuilder/pybuilder/issues/609) – user6106573 Sep 18 '18 at 06:14

0 Answers0