Skip to content
Advertisement

Python unittest not recognizing tests

I’m trying to learn how to use the unittest framework in python. I keep getting the message below when I run my file containing the tests.

JavaScript

I’ve searched here and elsewhere and can’t figure out why it is not recognizing the tests. Each test starts with test and the other portions of the unittest seem to match what the documentation requires.

Here is the text of the script:

JavaScript

Any help is appreciated

Advertisement

Answer

If you move

JavaScript

To the end of the script, then it will work.

Update

Here is my speculation: when you called unittest.main() in the middle of the script, your test class has not been defined yet, thus unittest did not pick up any tests. By moving the unittest.main() to the end, or more precisely–after your define your test class, you make sure that unittest sees those tests.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement