Opened 7 years ago

Last modified 7 years ago

#6832 defect new

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

Reported by: Josh Wilcox Owned by:
Priority: normal Milestone:
Component: trial Keywords:
Cc: Jonathan Lange Branch:


With the following test module "":

import unittest

class example(unittest.TestCase):

    def test(self):

    def test_(self):

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_ ...                                                              [OK]

Ran 1 tests in 0.010s

This 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 7 years ago by DefaultCC Plugin

Cc: Jonathan Lange added

comment:2 Changed 7 years ago by Josh Wilcox

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 7 years ago by Jean-Paul Calderone

Priority: lownormal

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 7 years ago by Jean-Paul Calderone

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.