def run_unit_tests(): """ Discover all unit test cases located in the test directory and run """ test_dir = os.path.dirname(__file__) top_dir = os.path.dirname(os.path.dirname(test_dir)) test_loader = TestLoader() run_unittest(test_loader.discover(test_dir, pattern="unit_test.py"))
def findTestsInDirectory(path, recursive=True , pattern = "test*.py"): loader = TestLoader() test_suite = loader.discover(path , pattern = pattern) for (root, dirnames, filenames) in os.walk( path ): for directory in dirnames: test_suite.addTests(ErtTestRunner.findTestsInDirectory(os.path.join(root, directory), recursive , pattern)) return test_suite
def findTestsInDirectory(path, recursive=True, pattern="test*.py"): loader = TestLoader() test_suite = loader.discover(path, pattern=pattern) for (root, dirnames, filenames) in os.walk(path): for directory in dirnames: test_suite.addTests( ErtTestRunner.findTestsInDirectory(os.path.join(root, directory), recursive, pattern) ) return test_suite
def run(self, *args, **kwargs): testloader = TestLoader() testSuite = testloader.discover(self.test_suite, top_level_dir='src/main/python') test_result = ExtendedTeamcityTestRunner().run(testSuite) test_result.printResults() if test_result.wasSuccessful(): exit(0) else: exit(1)
def get_tests(d = '.'): T = TestLoader() t = T.discover(d) stack = [t] tests = [] while stack: s = stack.pop() for t in s: if isinstance(t, TestSuite): stack.append(t) else: tests.append(t) return [test_name(v) for v in tests] # all test qualified names from this dir
def runTestsInDirectory(path="."): loader = TestLoader() tests = loader.discover(path) testRunner = TextTestRunner() testRunner.run(tests)
# # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import os import sys if sys.version_info[:2] <= (2,6): from unittest2 import TestLoader, TextTestRunner else: from unittest import TestLoader, TextTestRunner testdir = os.path.split(os.path.abspath(__file__))[0] topdir = os.path.split(testdir)[0] libdir = os.path.join(topdir, 'lib') os.chdir(testdir) sys.path.insert(0, libdir) loader = TestLoader() tests = loader.discover('.', 'flow_*.py') runner = TextTestRunner(verbosity=2, buffer=True) runner.run(tests)
try: import mock except ImportError: raise ImportError("The BatchApps Python Client test suite requires " "the mock package to run on Python 3.2 and below.\n" "Please install this package to continue.") try: from teamcity import is_running_under_teamcity from teamcity.unittestpy import TeamcityTestRunner TC_BUILD = is_running_under_teamcity() except ImportError: TC_BUILD = False if __name__ == '__main__': if TC_BUILD: runner = TeamcityTestRunner() else: runner = TextTestRunner(verbosity=2) test_dir = os.path.dirname(__file__) top_dir = os.path.dirname(os.path.dirname(test_dir)) test_loader = TestLoader() suite = test_loader.discover(test_dir, pattern="unittest_*.py", top_level_dir=top_dir) runner.run(suite)
except ImportError: raise ImportError("The ADAL test suite requires the unittest2 " "package to run on Python 2.6 and below.\n" "Please install this package to continue.") else: from unittest import TestLoader, TextTestRunner if sys.version_info[:2] >= (3, 3, ): from unittest import mock else: try: import mock except ImportError: raise ImportError("The ADAL test suite requires the mock " "package to run on Python 3.2 and below.\n" "Please install this package to continue.") if __name__ == '__main__': runner = TextTestRunner(verbosity=2) test_dir = os.path.dirname(__file__) top_dir = os.path.dirname(os.path.dirname(test_dir)) test_loader = TestLoader() suite = test_loader.discover(test_dir, pattern="test_*.py", top_level_dir=top_dir) runner.run(suite)
import optparse import os import sys from xmlrunner import XMLTestRunner try: from unittest2 import TestLoader, TextTestRunner except ImportError: from unittest import TestLoader, TextTestRunner base_path = os.path.dirname(__file__) parser = optparse.OptionParser() parser.add_option("-x", "--xml-prefix", dest="xml_prefix", help="generate XML test report in given directory", default=None) (options, args) = parser.parse_args() loader = TestLoader() tests = loader.discover(os.path.join(base_path, 'cvmfs/test'), pattern='*_test.py') runner = None if options.xml_prefix: runner = XMLTestRunner(output=options.xml_prefix, verbosity=2) else: runner = TextTestRunner(verbosity=2) runner.run(tests)
import sys import os from os.path import dirname, pardir, join, realpath cwd = dirname(realpath(__file__)) runtime = realpath(join(cwd, pardir, pardir, 'msrest')) sys.path.append(runtime) if sys.version_info[:2] < (2, 7, ): try: from unittest2 import TestLoader, TextTestRunner except ImportError: raise ImportError("The Python Client Runtime test suite requires " "the unittest2 package to run on Python 2.6 and " "below.\nPlease install this package to continue.") else: from unittest import TestLoader, TextTestRunner if __name__ == '__main__': runner = TextTestRunner(verbosity=2) test_dir = os.path.dirname(__file__) test_loader = TestLoader() suite = test_loader.discover(test_dir, pattern="unittest_*.py") runner.run(suite)
import os import sys from xmlrunner import XMLTestRunner try: from unittest2 import TestLoader, TextTestRunner except ImportError: from unittest import TestLoader, TextTestRunner base_path = os.path.dirname(__file__) parser = optparse.OptionParser() parser.add_option("-x", "--xml-prefix", dest="xml_prefix", help="generate XML test report in given directory", default=None) (options, args) = parser.parse_args() loader = TestLoader() tests = loader.discover(os.path.join(base_path, 'cvmfs/test'), pattern='*_test.py') runner = None if options.xml_prefix: runner = XMLTestRunner(output=options.xml_prefix, verbosity=2) else: runner = TextTestRunner(verbosity=2) runner.run(tests)
# You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import os import sys if sys.version_info[:2] <= (2, 6): from unittest2 import TestLoader, TextTestRunner else: from unittest import TestLoader, TextTestRunner testdir = os.path.split(os.path.abspath(__file__))[0] topdir = os.path.split(testdir)[0] libdir = os.path.join(topdir, 'lib') os.chdir(testdir) sys.path.insert(0, libdir) loader = TestLoader() tests = loader.discover('.', 'flow_*.py') runner = TextTestRunner(verbosity=2, buffer=True) runner.run(tests)
# # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import os import sys if sys.version_info[:2] <= (2,6): from unittest2 import TestLoader, TextTestRunner else: from unittest import TestLoader, TextTestRunner testdir = os.path.split(os.path.abspath(__file__))[0] topdir = os.path.split(testdir)[0] libdir = os.path.join(topdir, 'lib') os.chdir(testdir) sys.path.insert(0, libdir) loader = TestLoader() tests = loader.discover('.', 'test_*.py') runner = TextTestRunner(verbosity=2, buffer=True) runner.run(tests)