import unittest from testgears import collector name_doesnt_matter_for_testcases = False value = False module_setup_called = False def setup_module(module): global module_setup_called module_setup_called = True def test_testsInFileOrder(): "Tests are run in file order, part 1" global value value = True def test_arethey(): "Are they actually in order?" assert value def test_suiteproperties(): "Generated suite should look right" c = collector.Collector("testdata") t1 = c._tests[1] assert isinstance(t1, collector.FunctionTest) assert t1.func.func_name == "test_bIsFirst" t0 = c._tests[0] assert isinstance(t0, unittest.TestSuite) def test_regexmatching(): "Tests can be required to match a regex in the filename or testname" c = collector.Collector("testdata", regex=".*bIsFirst") assert len(c._tests) == 1 c = collector.Collector("testdata", regex=".*justatest") assert len(c._tests) == 3 class TestNormalCase(unittest.TestCase): def setUp(self): self.foo = 1 def test_setupiscalled(self): """Setup is called, as it is for normal unittest cases""" self.assertEquals(1, self.foo) def test_testcasebeforefuncs(self): 'TestCases are called before functions' self.failIf(value) class NamesDontMatterForTestCases(unittest.TestCase): def test_thisshouldbecalled(self): "TestCase classes should be used regardless of their name" global name_doesnt_matter_for_testcases name_doesnt_matter_for_testcases = True def test_was_it_called(): "TestCase classes should be used regardless of their names" assert name_doesnt_matter_for_testcases def test_module_setup(): "setup_module should be called" assert module_setup_called def teardown_module(module): pass