-1

So I tried many things (from SO and more) getting my tests running but nothing worked this is my current code:

test.py which I call to run the tests: python3 ./src/preprocess/python/test.py import unittest

if __name__ == '__main__':
    testsuite = unittest.TestLoader().discover('.')
    unittest.TextTestRunner(verbosity=2).run(testsuite)

the test file looks like this:

import unittest
from scrapes.pdf import full_path_to_destination_txt_file

print(full_path_to_destination_txt_file)

class PreprocessingTest(unittest.TestCase):

    def path_txt_appending(self):
        self.assertEqual(full_path_to_destination_txt_file(
            "test", "/usr/test"), "/usr/test/test.txt")


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

But the output is always like this:

python3 ./src/preprocess/python/test.py

----------------------------------------------------------------------
Ran 0 tests in 0.000s

OK

Additional Information:

  • As you can see I call this not from my root directory. The test folder is in ./src/preprocess/python/test/ and has a __init__.pyfile included (there is also a init file on the level of test.py)
  • it would be okay for me if I have to code down all the calls for all the tests I just want to finish this
  • automatic search with -t does not work either so I thought the more robust method here with test.py would work...
  • using this framework is a requirement I have to follow
  • test_preprocessing.py is in the test folder and from scrapes.pdf import full_path_to_destination_txt_filescrapes is a module folder on the same level as test
  • When I call the single unit test directly in the command line it fails because of the relative import. But using the test.py (obviously) finds the modules.

What is wrong?

rufreakde
  • 542
  • 4
  • 17

1 Answers1

2

By default, unittest will only execute methods whose name starts with test:

testMethodPrefix

String giving the prefix of method names which will be interpreted as test methods. The default value is 'test'. This affects getTestCaseNames() and all the loadTestsFrom*() methods.

from the docs.

Either change that attribute or (preferably) prefix your method name with test_.

DeepSpace
  • 78,697
  • 11
  • 109
  • 154