-1

From the question on running a single test via command line when tests are located within a sibling folder, the answer suggests using the -v option alongside the module name and test name to run a specific test.

Why does the -v option make this work? Specifying the module name and the test name makes sense since it corresponds to the unittest documnetation and obviously you need to specify which test to run. However, from what I can tell, the -v option corresponds to verbose output which shouldn't change the tests that the unittest module runs.

Apologies in advance if I've missed something obvious here.

Var
  • 36
  • 1
  • 4

1 Answers1

0

So the reason this wasn't working was because of a pretty obvious, but stupid, error on my part .

tldr; Use the full command line to run the tests (e.g. python3 -m unittest tests.module_name.TestClass.test_func) or if you're using a bash function, make sure the function accepts other arguments.


I had setup a bash function called run_tests to run unittests and I was trying to specify the module name and test name after calling that method. I.e. I had the following in .bash_profile:

run_tests ()
{
    python3 -m unittest
}

and on the terminal, I did:

run_tests tests.module_name.TestClass.test_func

Since the bash function was not setup to accept arguments, the specific test I wanted to run wasn't actually being passed as an argument to unittest.

Obviously, using -v makes no difference if you use the run_tests function to try and run a specific test.

When I tested with the -v option, I used the full command python3 -m unittest -v tests.module_name.TestClass.test_func which is why I thought the -v option made it work. To test whether the -v option actually worked, I was lazy and ran run_tests tests.module_name.TestClass.test_func again since it was in my shell history instead of typing out the full command, which is what caused this confusion.

Var
  • 36
  • 1
  • 4