简体   繁体   中英

Python unit-test running oddity with Eclipse and PyDev

I have created a Pydev project following this layout:

- project_root/
  |- setup.py
  |- my_package/
     |- __init__.py
     |- my_module.py
     |- tests/
        |- __init__.py
        |- test_my_module.py

The project_root directory was added to PYTHONPATH during project creation.

The my_package/my_module.py file has a class:

class MyClass(object):
    def my_method(self):
        return 1

And my_package/tests/test_my_module.py is supposed to contain test cases for this module:

import unittest
from my_package.my_module import MyClass

class MyClassTestCase(unittest.TestCase):
    def test_my_method(self):
        my_object = MyClass()
        self.assertEqual(1, my_object.my_method())

When I ran the tests from within Eclipse (Run As --> Python unit-test) with PyDev test runner and with Nose test runner -- it worked well.

But I also wanted to run it from command line, so I cd'd into project_root and tried:

> set PYTHONPATH=full/path/to/project_root
> nosetests --verbosity 2
...
ImportError: No module named my_module
> python -m unittest discover
...
ImportError: No module named my_module

Any idea on what might be the problem?

My environment details: Windows 7 x64 (but all relevant application installed as x86 applications), Eclipse Helios with JDK 1.7 and PyDev 2.2.3, Python 2.7.2, project configured to run in virtualenv, installed virtualenv is 1.6.4, nose 1.1.2.

How strange. Nothing's changed in the environment or settings, but the problem disappeared.

Running the tests using nosetests or unittest.discover from PyDev or from command line works OK...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM