I have a test file and a main module file in which there's a function I'm testing. At the end of my test file, I have unittest.main() to run the unit tests.
When I run the test file, the console shows "No tests were found". This problem seems to go away when I:
(1) Enclose the unittest.main() inside an if __name__ == "__main__" (I sort of understand how this clause works, but it makes no sense for me in this case, when the unittest.main() module runs properly when there's an if clause, versus when there's no coditional at all), OR
(2) When I run my test program in Spyder
Therefore, this seems like an issue specific to Pycharm. As a result, what do I need to do/configure to get unittest.main run properly?
For your reference, here are the 2 files in my program; my test file returns no test as opposed to the 2 tests that I'd programmed for it.
---Main file: city_functions.py---
def print_city_country(city, country, population=""):
"""Print 'city, country' from input city and country"""
formatted_city_country = city + ", " + country + " - population " + str(population)
formatted_city_country = city + ", " + country
---Test file: test_cities.py---
from city_functions import print_city_country
"""Test function city_country from city_functions module"""
"""Test for names like Santiago, Chile without population input"""
formatted_city_country = print_city_country("Santiago", "Chile")
self.assertEqual(formatted_city_country, "Santiago, Chile")
"""Test for names like Ho Chi Minh City, Vietnam, 8400000"""
formatted_city_country_population = print_city_country("Santiago", "Chile", 8400000)
self.assertEqual(formatted_city_country_population, "Santiago, Chile - population 8400000")