Simple unittest doesn't work in pycharm python

Viewed 295

When I try to do simple unittest in pycharm, It doesn't work, the output is "Ran 0 Tests in 0.000s" and when I'm doing exactly same thing in Geany, it works, "Ran 1 Test in 0.000s" can someone figure out why?

import unittest

class Test(unittest.TestCase):
    def test_cos_tam(self):

        r = '200'
        self.assertEqual(r, '200')

unittest.main()
C:\Users\wycze\Desktop\python_work\WizualizacjaDanych\Scripts\python.exe "D:\pycharm\PyCharm Community Edition 2020.3.2\plugins\python-ce\helpers\pycharm\_jb_unittest_runner.py" --path C:/Users/wycze/Desktop/python_work/WizualizacjaDanych/test_python_repos.py
Testing started at 23:45 ...

----------------------------------------------------------------------
Launching unittests with arguments python -m unittest C:/Users/wycze/Desktop/python_work/WizualizacjaDanych/test_python_repos.py in C:\Users\wycze\Desktop\python_work\WizualizacjaDanych
Ran 0 tests in 0.000s


OK

Process finished with exit code 0

Empty suite

Empty suite
1 Answers

Inspired by this answer and some of my own test code I reformatted the folders to be:

C:\USERS\ME\DESKTOP\SO_TEST2
└───src
    └───test
            test_python_repos.py
            __init__.py

with an empty __init__.py file. I also added a conditional on the last line of your test file:

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

because I don't think you want that to run unless you run the tests directly. I'm now able to cd into the src directory and run:

python -m unittest with the following result:

.
----------------------------------------------------------------------
Ran 1 test in 0.000s

OK

Hopefully that is of some use to you...

Related