Search code examples
pythonpython-unittestpybuilder

PyBuilder: No unit tests executed


Suppose that this is the layout of the source directory of my PyBuilder project (empty __init__.py in myProject omitted):

src
├── main
│   └── python
│       └── myProject
│           └── usefulThing.py
└── unittest
    └── python
        └── UsefulThingTest.py

and the content of UsefulThingTest.py is as follows:

import unittest

from myProject.usefulThing import usefulFunction

class UsefulThingTest(unittest.TestCase):

  def test_should_do_useful_things(self):
    self.assertEqual(usefulFunction(42), 1764)

When I run pyb, I get the following warnings, and no tests are executed:

[WARN]  No unit tests executed.
[INFO]  All unit tests passed.

Why doesn't PyBuilder run those tests?


Solution

  • The fact that the UsefulThingTest-class extends unittest.TestCase is not sufficient for the class to be run as a test. The name of the file in which UsefulThingTest is saved must also follow a convention: by default, it must end with _tests.py. For example, renaming:

    UsefulThingTest.py
    

    to

    useful_thing_tests.py
    

    fixes the problem.

    Quote from the Tutorial:

    The file must end with _tests.py. This tells PyBuilder to consider this file when discovering test cases.

    This can be altered by setting the unittest_file_suffix property as described here.