In my UnitTest directory, I have two files, mymath.py and test_mymath.py.
mymath.py file:
def add(a, b):
    return a + b
def subtract(a, b):
    return a - b
def multiply(a, b):
    return a * b
def divide(numerator, denominator):
    return float(numerator) / denominator
And the test_mymath.py file is:
import mymath
import unittest
class TestAdd(unittest.TestCase):
    """
    Test the add function from the mymath library
    """
    def test_add_integer(self):
        """
        Test that the addition of two integers returns the correct total
        """
        result = mymath.add(1, 2)
        self.assertEqual(result, 3)
    def test_add_floats(self):
        """
        Test that the addition of two integers returns the correct total
        """
        result = mymath.add(10.5, 2)
        self.assertEqual(result, 12.5)
    def test_add_strings(self):
        """
        Test that the addition of two strings returns the two strings as one
        concatenated string
        """
        result = mymath.add('abc', 'def')
        self.assertEqual(result, 'abcdef')
if __name__ == '__main__':
    unittest.main()
When I run the command
python .\test_mymath.py
I got the results
Ran 3 tests in 0.000s
OK
But when I tried to run the test using
python -m unittest .\test_mymath.py
I got the error
ValueError: Empty module name
Traceback:

Folder Structure:

I am following this article
My python version is Python 3.6.6 and I am using windows 10 in the local machine.
Use python -m unittest test_mymath
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With