0

I have inherited a testing directory that looks like this:

tests
  | this_test
    | __init__.py
    | this_test.py  
  | that_test
    | __init__.py
    | that_test.py

Where the __init.py__'s are empty and both this_test.py and that_test.py look like this:

from unittest import TestCase

class TestingThis(TestCase):

    def test_testing(self):
        self.assertTrue(1, 1)

They really are that simple. But my confusion comes from figuring out how to run these. I've always seen tests like:

import unittest

class TestingThis(unittest.TestCase):

    def test_testing(self):
        self.assertTrue(1, 1)

if __name__ == '__main__':
    unittest.main()

Which I can run from terminal in the directory with python3 this_test.py. I've tried a multitude of ways to run these in terminal but with no success and haven't found anything in my search that shows this pattern.

Is this an actual design pattern for tests, or do these just need fixed?

DjH
  • 1,348
  • 1
  • 19
  • 39

2 Answers2

0

You can use nosetests coming from package nose to discover and run your tests. It is very useful to collect and run all tests, even coming from docstring. Also, you can generate JUnit XML report with it.

pip install nose
# Show all nosetests options
nosetests --help
cd tests
nosetests
Guillaume Jacquenot
  • 10,118
  • 5
  • 41
  • 48
0

You can use nose for running the tests, and start the name of your test files with 'test_' , so that nose can discover the test files and test inside them.

Example - test_this.py

Shashank
  • 565
  • 4
  • 15