0

I'd like to run a single test contained in a subclass of unittest.TestCase using nose2 following How to run specific test in Nose2, but it doesn't seem to work for me. I'm using the following example script, which I've named mickey_mouse_test.py:

import unittest

class TestMickeyMouse(unittest.TestCase):
    def test_1plus1is2(self):
        self.assertTrue(1+1 == 2)

    def test_to_uppercase(self):
        self.assertEqual("hello".upper(), "HELLO")

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

If I run nose2 mickey_mouse_test in the same directory, it runs all the tests in the module:

kurt@kurt-ThinkPad:~/Documents/Scratch$ nose2 mickey_mouse_test
..
----------------------------------------------------------------------
Ran 2 tests in 0.001s

OK

However, if I try to run just test_to_uppercase like so I get an error:

kurt@kurt-ThinkPad:~/Documents/Scratch$ nose2 mickey_mouse_test.test_to_uppercase
E
======================================================================
ERROR: mickey_mouse_test.test_to_uppercase (nose2.loader.LoadTestsFailure)
----------------------------------------------------------------------
AttributeError: module 'mickey_mouse_test' has no attribute 'test_to_uppercase'

----------------------------------------------------------------------
Ran 1 test in 0.001s

FAILED (errors=1)

If I use the -s option I still get an error, albeit a different one:

kurt@kurt-ThinkPad:~/Documents/Scratch$ nose2 -s mickey_mouse_test.test_to_uppercase
E
======================================================================
ERROR: mickey_mouse_test.test_to_uppercase (nose2.loader.LoadTestsFailure)
----------------------------------------------------------------------
OSError: /home/kurt/Documents/Scratch/mickey_mouse_test.test_to_uppercase is not a directory

----------------------------------------------------------------------
Ran 1 test in 0.000s

FAILED (errors=1)

I've also tried reading the "Specifying tests to run" section in http://nose2.readthedocs.io/en/latest/usage.html, in which it is stated that the 'Python object part' should be a 'dotted name'. I don't see why in this case, mickey_mouse_test.test_to_uppercase is not a 'dotted name'. Any ideas why this is not working?

Community
  • 1
  • 1
Kurt Peek
  • 52,165
  • 91
  • 301
  • 526
  • Does this answer your question? [How to run specific test in Nose2](https://stackoverflow.com/questions/17890087/how-to-run-specific-test-in-nose2) – Pamplemousse Mar 26 '20 at 20:38

1 Answers1

-1

Here is a way to run just test_to_uppercase without using nose2 (following Running single test from unittest.TestCase via command line):

kurt@kurt-ThinkPad:~/Documents/Scratch$ python mickey_mouse_test.py TestMickeyMouse.test_to_uppercase
.
----------------------------------------------------------------------
Ran 1 test in 0.000s

OK
Community
  • 1
  • 1
Kurt Peek
  • 52,165
  • 91
  • 301
  • 526