2

This is my first project in Python and I have just learnt the unittest framework. The test module runs well when I do python test_module.py but when I want to execute a certain class or a method as said in the documentation using:

python -m unittest test_module.TestClass.test_method  # or even just test_module

I get the following error:

AttributeError: 'module' object has no attribute 'test_module'

The directory where I run the command contains graphm_test.py (I also tried to change the name to test_graphm.py), with class graphm_test(unittest.TestCase): and methods all starting with test_* and here is the command I run on the terminal:

python -m unittest test_graphm.py

I could not find a similar problem to this anywhere, it would be great to know the reason behind the error and how to run a certain class inside the module or a certain method

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
Abdallah Sobehy
  • 2,881
  • 1
  • 15
  • 28
  • 2
    Consider using nosetest as your test runner instead. – Marcin Sep 04 '15 at 16:21
  • Related: http://stackoverflow.com/questions/15971735/running-single-test-from-unittest-testcase-via-command-line and http://stackoverflow.com/questions/1068246/python-unittest-how-to-run-only-part-of-a-test-file – alecxe Sep 04 '15 at 16:24

1 Answers1

0

There are 2 issues: you are not calling the correct module name, and you are using the extension .py.

So you need to be in the folder with your graphm_test.py file, and run:

python -m unittest graphm_test
DevShark
  • 8,558
  • 9
  • 32
  • 56