Python nose2 unit tests with circle.yml

python
circle.yml

#1

Hey all,

I’m trying to run python unit tests with nose2 through circle.yml configuration. However, nose2 is failing to discover tests when running on circle ci, even though it works locally.

All of the python code is contained one directory up from the root of the repo, in a directory called python_directory. So we’d like to specifiy the start directory for nose2.

Here’s my circle.yml file:

machine:
  python:
    version: 2.7.10
  environment:
    PYTHONPATH: ${HOME}/repo_name/python_directory

dependencies:
  pre:
    - easy_install -U setuptools
    - pip install -r python_directory/python_req.txt

test:
  override:
    - echo $PYTHONPATH
    - cd python_directory/ && pwd s&& nose2

Here’s the output from echo $PYTHONPATH:

/home/ubuntu/repo_name/python_directory

And here’s the output from running the tests. The name of the file that nose2 should find is test_config.py:

/home/ubuntu/repo_name/python_directory
E
======================================================================
ERROR: test_config (nose2.loader.ModuleImportFailure)
----------------------------------------------------------------------
ImportError: Failed to import test module: test_config
Traceback (most recent call last):
  File "/home/ubuntu/virtualenvs/venv-2.7.10/lib/python2.7/site-packages/nose2/plugins/loader/discovery.py", line 200, in _find_tests_in_file
    module = util.module_from_name(module_name)
  File "/home/ubuntu/virtualenvs/venv-2.7.10/lib/python2.7/site-packages/nose2/util.py", line 80, in module_from_name
    __import__(name)
ImportError: No module named test_config



----------------------------------------------------------------------
Ran 1 tests in 0.001s


FAILED (errors=1) cd python_directory/ && pwd && nose2 returned exit code 1

It looks like it’s running nose2 from the correct directory, yet it still can’t find the test.

Any ideas on what the correct way to set up nose2 unit tests is?


Python unittest discover works over SSH but not from circle.yml
#2

Hi JKane,

I’m running into the same problem myself. Did you manage to resolve it?


#3