Why "No tests were found"

This is the code I typed from the book, and when I run it, the compiler displays “No tests were found”. What is the reason for this? How to solve it?

names.py

from name_function import get_formatted_name

print("Enter 'q' to quit")
while True:
    first = input("Enter your first name: ")
    if first == 'q':
        break
    last = input("Enter your last name: ")
    if last == 'q':
        break
    formatted_name = get_formatted_name(first, last)
    print("\tNeatly formatted name: " + formatted_name + '.')

name_function.py

def get_formatted_name(first, last):
    """Generate well-organized full names"""
    full_name = first + ' ' + last
    return full_name.title()

test_name_function.py

import unittest
from name_function import get_formatted_name

class NameTestCase(unittest.TestCase):
    """Test name_function.py"""

    def test_first_last_name(self):
        """Can it handle names like Janis Joplin correctly"""
        formatted_name = get_formatted_name('janis', 'joplin')
        self.assertEqual(formatted_name, 'Janis Joplin')

 unittest.main()

No; the program that you use to test your code displays this.

In order to understand why, we need to see the steps that you take, to try running the code. It looks like you are trying to use unittest from the standard library, but indirectly through the IDE. I can’t tell what IDE this is.

Please also read the pinned thread and show the code as properly formatted text.

I’m sorry, I have already displayed the code as formatted text. I use PyCharm as my IDE.

In my test code, when I place ‘unittest.main()’ inside the " if name == 'main ’ " block, the program works fine. Why is that?

import unittest
from name_function import get_formatted_name

class NameTestCase(unittest.TestCase):
    """Test name_function.py"""

    def test_first_last_name(self):
        """Can it handle names like Janis Joplin correctly"""
        formatted_name = get_formatted_name('janis', 'joplin')
        self.assertEqual(formatted_name, 'Janis Joplin')

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