# Python nose2 unit tests with circle.yml

**URL:** <https://discuss.circleci.com/t/python-nose2-unit-tests-with-circle-yml/2494>\
**Category:** Programming Languages\
**Tags:** python, circle-yml\
**Created:** [March 3, 2016, 9:58pm UTC](https://discuss.circleci.com/t/python-nose2-unit-tests-with-circle-yml/2494 "2016-03-03T21:58:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![JKane](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/jkane/32/19504_2.png) [@JKane](https://discuss.circleci.com/u/JKane)\
**Post date:** [March 3, 2016, 9:58pm UTC](https://discuss.circleci.com/t/python-nose2-unit-tests-with-circle-yml/2494/1 "2016-03-03T21:58:53Z")

</div>

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:

```auto
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`:

```auto
/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:

```auto
/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?

---

<div class="post-metadata">

**Author:** ![aidan-duggan](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/aidan-duggan/32/16377_2.png) [@aidan-duggan](https://discuss.circleci.com/u/aidan-duggan)\
**Post date:** [June 22, 2017, 3:09pm UTC](https://discuss.circleci.com/t/python-nose2-unit-tests-with-circle-yml/2494/2 "2017-06-22T15:09:11Z")

</div>

Hi JKane,

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

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/circleci/original/3X/5/1/511608acda8e85906e15909b57bd0a46c1dbe291.png) [@system](https://discuss.circleci.com/u/system)\
**Post date:** [June 18, 2018, 11:33am UTC](https://discuss.circleci.com/t/python-nose2-unit-tests-with-circle-yml/2494/3 "2018-06-18T11:33:04Z")

</div>


