2

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?

Andrey Tyukin
  • 43,673
  • 4
  • 57
  • 93

2 Answers2

2

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.

Andrey Tyukin
  • 43,673
  • 4
  • 57
  • 93
0

unittests require file (containing tests) to be named as: *_tests.py

And it also imposes restrictions on functions name:

import unittest
class SampleTests(unittest.TestCase):
      def test1(self):
          #function name should be like this : no underscore etc.

i.e They have predefined naming conventions for test suite