Opened 2 years ago

Last modified 2 years ago

#6832 defect new

unittest 's test runner has a different criteria for test case names than trial

Reported by: Zancas Owned by:
Priority: normal Milestone:
Component: trial Keywords:
Cc: jml Branch:
Author: Launchpad Bug:

Description

With the following test module "test_demo.py":

import unittest

class example(unittest.TestCase):

    def test(self):
        pass

    def test_(self):
        pass

I generate different results with the two runners "unittest":

$ python -m unittest -v test_demo
test (test_demo.example) ... ok
test_ (test_demo.example) ... ok

----------------------------------------------------------------------
Ran 2 tests in 0.000s

and "trial":

$ trial test_demo.py
test_demo
  example
    test_ ...                                                              [OK]

-------------------------------------------------------------------------------
Ran 1 tests in 0.010s

This http://docs.python.org/2/library/unittest.html suggests that the string "test" by itself is sufficient to designate a TestCase method to be a "test case":

"A testcase is created by subclassing unittest.TestCase. The three individual tests are defined with methods whose names start with the letters test. This naming convention informs the test runner about which methods represent tests."

Change History (4)

comment:1 Changed 2 years ago by DefaultCC Plugin

  • Cc jml added

comment:2 Changed 2 years ago by Zancas

I also realize that a test case named 'test' is a degenerate case, and it's possible that ignoring it is the correct behavior.

comment:3 Changed 2 years ago by exarkun

  • Priority changed from low to normal

Strictly speaking this is probably a difference in the behavior of the loaders.

This seems to be a result of twisted.python.reflect.prefixedMethodNames which specifically excludes methods that exactly equal the prefix.

I'm not sure I'm terribly interested in this divergence but it does seem a shame that trial might sometimes miss running tests that the stdlib toolchain will run (since it might be a reason for some people not to start using trial, and I hate it when there are reasons for that).

comment:4 Changed 2 years ago by exarkun

For what it's worth, this behavior is implemented by twisted.trial.runner.TestLoader.getTestCaseNames and unittest.loader.TestLoader.getTestCaseNames.

Note: See TracTickets for help on using tickets.