开发者

Python unit-test running oddity with Eclipse and PyDev

开发者 https://www.devze.com 2023-04-13 00:55 出处:网络
I have created a Pydev project following this layout: - project_root/ |- setup.py |- my_package/ |- __init__.py

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 with开发者_JAVA技巧in 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...

0

精彩评论

暂无评论...
验证码 换一张
取 消