python plugin: how to enable context menu to run all unit tests in folder?

Hi All,

We are still enjoying using the Python plugin 2.10.0 in IDEA 12.0.1 on Mac OS X 10.6.8. I'd appreciate your help figuring out how to enable a feature I've seen working before, but can't get to work again: Getting this context menu to show: 'Run 'Unittests in ..."'. To demonstrate the problem:

  • Create a new project with a Python Module (we are using Python 3.2.3). Don't select any facets.
  • Create a new Python Package (context menu) named 'main'. Repeat to create one named 'test'.
  • Mark the first folder as Source Root and the latter as Test Source Root.
  • In the test folder create a Python file named test-foo whose Kind is Python unit test.
  • Show the context menu fo the test folder. Notice that it does not offer the option to 'Run 'Unittests in ..."'.


Thanks in advance,

matt

0

AHA! I discovered the causes of the problem, which I'll share to get some feedback, and in case anyone else has it. There were two requirements:

1. .idea/testrunner.xml had 'Nosetests' instead of 'Unittests'. This is controlled by: Project Settings > Python Integrated Tools > Default test runner: Unittests. E.g.,
    <option name="projectConfiguration" value="Unittests" />
    <option name="PROJECT_TEST_RUNNER" value="Unittests" />

2. there had to be a placeholder file in the test directory:
    import unittest
    class Placeholder(unittest.TestCase):
        pass

Surprises:

  • I think the latest IntelliJ 12 added or modified the above Default test runner behavior.
  • For the single-level test directory, the placeholder did not have to inherit from TestCase. However, TestCase was required for nested ones.
  • Test files in the nested case must be named test*.
  • The test directory did not have to be marked as a Test Source Root.


So the correct sequence to create a working test directory runner is:

1. Create a new project with a Python Module (we are using Python 3.2.3). Don't select any facets.

2. Create this project file structure. File contents listed below [1].
    .idea/
    main/
        __init__.py
        foo.py
    test/
        main/
            test-foo.py
        placeholder-for-tests.py


3. Change the project's Default test runner from Nosetests to Unittests (Project Settings > Python Integrated Tools > Default test runner)

4. Show the context menu for the test folder and select 'Run > Unittests in ...'.


Works for me! JetBrains: Would you please comment on why it has to be done this way? It was not straightforward. Thanks -- matt


[1] File contents:

# __init__.py:
# empty


# foo.py:
class Foo(object):
def doit(self):
    return 1

# test-foo.py:
from main.foo import Foo
import unittest
class FooTest(unittest.TestCase):
    def testFoo(self):
        self.assertEqual(1, Foo().doit())

# placeholder-for-tests.py:
import unittest
class Placeholder(unittest.TestCase):
    pass

1

请先登录再写评论。