The Python unittest (which Flask uses behind the scenes) organizes the code in a special way.
To run a specific method from a class derived from TestCase , you need to do the following:
LoginResourceHelper('test_create_and_login_user').test_create_and_login_user(email, password)
What is not suitable for the scene
To understand why you should do this, you need to understand how the default TestCase object works.
Typically, when inherited, TestCase expects the runTest method to be runTest :
class ExampleTestCase(TestCase): def runTest(self):
However, if you need to have several TestCases , you will need to do this for each of them.
Since this is a tedious thing, they decided the following:
class ExampleTestcase(TestCase): def test_foo(self):
This is called a test fixture. But since we did not declare runTest() , now you must specify which method you want to run TestCase, this is what you want to do.
>>ExampleTestCase('test_foo').test_foo() >>ExampleTestCase('test_bar').test_bar()
Typically, the unittest module will do all this on the back, as well as some other things:
- Adding test packages to a test suite (which is usually done using TestLoader)
- Calling the correct TestRunner (which will run all the tests and report the results)
But since you unittest normal execution of unittest , you must do the work that unitest does regularly.
For a really deep understanding, I highly recommend you read unittest docs .