Esempio n. 1
0
def load_tests_from_classes(test_cases):
    suite = TestSuite()
    loader = TestLoader()
    for test_class in test_cases:
        tests = loader.loadTestsFromTestCase(test_class)
        suite.addTests(tests)
    return suite
Esempio n. 2
0
def run_test(path: str = 'testcase'):
    """
    :param path: With default path testcase, the method will execute all testcases, otherwise it only execute the
    cases which in the specific path
    :return: test report
    """
    report_name = "{}_{}".format(path,
                                 str(datetime.now().strftime("%Y%m%d%H%M")))
    testsuits = TestSuite()

    if path == 'testcase':
        for dir in os.listdir(os.path.join(os.curdir, path)):
            testsuits.addTests(
                unittest.defaultTestLoader.discover(dir,
                                                    pattern='*test.py',
                                                    top_level_dir='testcase'))
    else:
        testsuits.addTests(
            unittest.defaultTestLoader.discover(path,
                                                pattern='*test.py',
                                                top_level_dir='testcase'))

    result = BeautifulReport(testsuits)
    result.report(filename=report_name, description=path, log_path='result')
    shutil.copy('result/%s.html' % report_name, 'result/test_api_ressult.html')
    if result.failure_count or result.error_count:
        #主动出发失败导致jenkins失败
        raise Exception("主动失败,发送邮件")
Esempio n. 3
0
def load_tests(loader, tests, pattern):
    suite = TestSuite()
    suite.addTests(load_testsuite(loader, dirname(__file__)))
    # Numba CUDA tests are located in a separate directory:
    cuda_dir = join(dirname(dirname(__file__)), 'cuda/tests')
    suite.addTests(loader.discover(cuda_dir))
    return suite
Esempio n. 4
0
 def load_tests(loader: TestLoader, standard_tests: TestSuite,
                pattern: Optional[str]) -> TestSuite:
     ret = TestSuite((standard_tests, ))
     for cls in tests:
         suite = loader.loadTestsFromTestCase(cls)
         ret.addTests(suite)
     return ret
Esempio n. 5
0
def load_tests_from_classes(test_cases):
    suite = TestSuite()
    loader = TestLoader()
    for test_class in test_cases:
        tests = loader.loadTestsFromTestCase(test_class)
        suite.addTests(tests)
    return suite
Esempio n. 6
0
def load_tests(loader, tests, pattern):
    suite = TestSuite()
    suite.addTests(load_testsuite(loader, dirname(__file__)))
    # Numba CUDA tests are located in a separate directory:
    cuda_dir = join(dirname(dirname(__file__)), 'cuda/tests')
    suite.addTests(loader.discover(cuda_dir))
    return suite
Esempio n. 7
0
    def _get_suite(self, test_labels, discover_kwargs, extra_tests, methods):
        suite = TestSuite()
        for label in test_labels:
            kwargs = discover_kwargs.copy()
            tests = None

            label_as_path = os.path.abspath(label)

            # if a module, or "module.ClassName[.method_name]", just run those
            if not os.path.exists(label_as_path):
                tests = self.test_loader.loadTestsFromName(label)
            elif os.path.isdir(label_as_path) and not self.top_level:
                # Try to be a bit smarter than unittest about finding the
                # default top-level for a given directory path, to avoid
                # breaking relative imports. (Unittest's default is to set
                # top-level equal to the path, which means relative imports
                # will result in "Attempted relative import in non-package.").

                # We'd be happy to skip this and require dotted module paths
                # (which don't cause this problem) instead of file paths (which
                # do), but in the case of a directory in the cwd, which would
                # be equally valid if considered as a top-level module or as a
                # directory path, unittest unfortunately prefers the latter.

                top_level = label_as_path
                while True:
                    init_py = os.path.join(top_level, '__init__.py')
                    if os.path.exists(init_py):
                        try_next = os.path.dirname(top_level)
                        if try_next == top_level:
                            # __init__.py all the way down? give up.
                            break
                        top_level = try_next
                        continue
                    break
                kwargs['top_level_dir'] = top_level

            if not (tests and tests.countTestCases()):
                # if no tests found, it's probably a package; try discovery
                tests = self.test_loader.discover(start_dir=label, **kwargs)

                # make unittest forget the top-level dir it calculated from this
                # run, to support running tests from two different top-levels.
                self.test_loader._top_level_dir = None

            tests = self.get_tests_defined_in_methods_or_none(tests, methods)
            if tests:
                suite.addTests(tests)

        for test in extra_tests:
            suite.addTest(test)
        return suite
Esempio n. 8
0
    def _get_suite(self, test_labels, discover_kwargs, extra_tests, methods):
        suite = TestSuite()
        for label in test_labels:
            kwargs = discover_kwargs.copy()
            tests = None

            label_as_path = os.path.abspath(label)

            # if a module, or "module.ClassName[.method_name]", just run those
            if not os.path.exists(label_as_path):
                tests = self.test_loader.loadTestsFromName(label)
            elif os.path.isdir(label_as_path) and not self.top_level:
                # Try to be a bit smarter than unittest about finding the
                # default top-level for a given directory path, to avoid
                # breaking relative imports. (Unittest's default is to set
                # top-level equal to the path, which means relative imports
                # will result in "Attempted relative import in non-package.").

                # We'd be happy to skip this and require dotted module paths
                # (which don't cause this problem) instead of file paths (which
                # do), but in the case of a directory in the cwd, which would
                # be equally valid if considered as a top-level module or as a
                # directory path, unittest unfortunately prefers the latter.

                top_level = label_as_path
                while True:
                    init_py = os.path.join(top_level, '__init__.py')
                    if os.path.exists(init_py):
                        try_next = os.path.dirname(top_level)
                        if try_next == top_level:
                            # __init__.py all the way down? give up.
                            break
                        top_level = try_next
                        continue
                    break
                kwargs['top_level_dir'] = top_level

            if not (tests and tests.countTestCases()):
                # if no tests found, it's probably a package; try discovery
                tests = self.test_loader.discover(start_dir=label, **kwargs)

                # make unittest forget the top-level dir it calculated from this
                # run, to support running tests from two different top-levels.
                self.test_loader._top_level_dir = None

            tests = self.get_tests_defined_in_methods_or_none(tests, methods)
            if tests:
                suite.addTests(tests)

        for test in extra_tests:
            suite.addTest(test)
        return suite
Esempio n. 9
0
 def run(self):
     global THIS_PATH, PKG_DIR, TEST_DIR
     
     sys.path.insert(0, PKG_DIR)
     
     suite = TestSuite()
     loaded = unittest.defaultTestLoader.discover(TEST_DIR, pattern='*Test.py')
     
     for all_test_suite in loaded:
         for test_suite in all_test_suite:
             suite.addTests(test_suite)
     
     runner = TextTestRunner(verbosity = 2)
     runner.run(suite)
Esempio n. 10
0
def main():
    dt_suite = doctest.DocTestSuite(test_finder=doctest.DocTestFinder(
        recurse=True))
    dt_suite.countTestCases()
    dt_suite.debug()
    if pytest is None:
        suite = TestSuite()
        all_test_suites = unittest.defaultTestLoader.discover(start_dir="test")
        suite.addTests(tests=[all_test_suites, dt_suite])
        logging.debug(vars(suite))
        successful = TextTestRunner().run(suite).wasSuccessful()
        return 0 if successful else 1
    else:
        pytest.main(plugins=[])
Esempio n. 11
0
def load_tests(loader, tests, pattern):
    suite = TestSuite()
    suite.addTests(load_testsuite(loader, dirname(__file__)))
    return suite
Esempio n. 12
0
    assert(self.device.GetPin(self.LED1).toChar() == "H")
    assert(self.device.GetPin(self.LED2).toChar() == "H")
    self.doRun(2500000) # 25ms
    assert(self.device.GetPin(self.LED1).toChar() == "H")
    assert(self.device.GetPin(self.LED2).toChar() == "H")
    # Deuxieme seconde
    self.doRun(2500000) # 25ms
    assert(self.device.GetPin(self.LED1).toChar() == "L")
    assert(self.device.GetPin(self.LED2).toChar() == "H")
    self.doRun(2500000) # 25ms
    assert(self.device.GetPin(self.LED1).toChar() == "L")
    assert(self.device.GetPin(self.LED2).toChar() == "H")
    self.doRun(2500000) # 25ms
    assert(self.device.GetPin(self.LED1).toChar() == "L")
    assert(self.device.GetPin(self.LED2).toChar() == "H")
    self.doRun(2500000) # 25ms
    assert(self.device.GetPin(self.LED1).toChar() == "L")
    assert(self.device.GetPin(self.LED2).toChar() == "H")
    self.doRun(2500000) # 25ms
    assert(self.device.GetPin(self.LED1).toChar() == "L")
    assert(self.device.GetPin(self.LED2).toChar() == "L")



if __name__ == "__main__":
  allTestsFrom = defaultTestLoader.loadTestsFromTestCase
  suite = TestSuite()
  suite.addTests(allTestsFrom(TestEx1Semaine2))
  TextTestRunner(verbosity = 2).run(suite)

Esempio n. 13
0
from unittest import TextTestRunner
from unittest.suite import TestSuite
from unittest.loader import TestLoader
from test_case_01 import TestCase01
from test_case_02 import TestCase02
from test_case_03 import TestCase03
from test_case_04 import TestCase04
from test_case_05 import TestCase05
from test_case_06 import TestCase06
from test_simulation import TestSimulation

if __name__ == "__main__":
    suite = TestSuite()
    loader = TestLoader()
    suite.addTests(loader.loadTestsFromTestCase(TestCase01))
    suite.addTests(loader.loadTestsFromTestCase(TestCase02))
    suite.addTests(loader.loadTestsFromTestCase(TestCase03))
    suite.addTests(loader.loadTestsFromTestCase(TestCase04))
    suite.addTests(loader.loadTestsFromTestCase(TestCase05))
    suite.addTests(loader.loadTestsFromTestCase(TestCase06))

    # run the suite
    debug_enabled = False
    if debug_enabled:
        """
        NOTE Using buffer=False and failfast=True together ensures that any exception occurring during test runs is printed
        to stderr immediately instead of being hold back until all test cases finished.
        However at least failfast has to be disabled if test cases contain tests that are expected to fail.
        """
        failfast = True
        buffer = False
Esempio n. 14
0
def load_tests(loader, tests, pattern):
    suite = TestSuite()
    suite.addTests(load_testsuite(loader, dirname(__file__)))
    return suite
Esempio n. 15
0
def do_test():
    print(f'当前时间:{datetime.datetime.now()}')
    project_cwd = get_absolute_path('testcase')
    report_path = project_cwd.joinpath(
        f'testsuits\\reports\\{time.strftime("%Y%m%d%H%M%S")}.html')
    fp = open(report_path, 'wb')
    suite = TestSuite()
    test01 = TestMainProcess('test_MainProcess_01')
    test02 = TestMainProcess('test_MainProcess_02')
    test03 = AddResourcesCase('test_add_resources')
    test04 = TestPackageCourse('test_package_course_01')
    test05 = TestPackageCourse('test_package_course_02')
    test06 = HomeworkLoop('test_homework_loop_01')
    test08 = HomeworkLoop('test_homework_loop_02')
    test10 = TestAddDraft('test_save_draft_loop')
    test11 = TestFieldCase('test_01')
    test12 = TestFieldCase('test_02')
    test13 = TestFieldCase('test_03')
    test14 = TestFieldCase('test_04')
    test15 = TestFieldCase('test_05')
    test16 = TestFieldCase('test_06')
    test17 = TestMyCreation('test_01')
    test18 = WorksHall('test_01')
    test19 = WorksHall('test_02')
    test20 = WorksHall('test_03')
    test21 = TestAIExperience('test_01')
    test22 = TestWishBox('test_wish_box')
    test23 = UserLoginWrong('test_wrong_login')
    test24 = TestErrorCheck('test_field_error')
    test25 = TestErrorCheck('test_course_field_error')

    suite.addTests([
        test01, test02, test03, test04, test05, test06, test08, test10, test11,
        test12, test13, test14, test15, test16, test17, test18, test19, test20,
        test21, test22, test23, test24, test25
    ])
    runner = HTMLTestRunner(stream=fp,
                            title='叮当码教育版2期ui自动化测试报告',
                            description='测试模块:标准授课,主题授课,试炼场,创作空间,AI体验')
    runner.run(suite)

    mail_server = EmailData.mail_server
    port = EmailData.port
    sender_email = EmailData.sender_email
    sender_password = EmailData.sender_password
    receive_email = EmailData.receive_email
    try:
        msg = MIMEMultipart('related')
        msg['From'] = formataddr(['sender', sender_email])
        msg['To'] = formataddr(['receiver', receive_email])
        msg['Subject'] = '自动测试报告'

        body = """
        <h1>UI自动化测试报告,详情见附件。</h1>
        """
        text = MIMEText(body, 'html', 'utf-8')
        msg.attach(text)

        file_path = f'{project_cwd.as_posix()}\\testsuits\\reports'
        zip_path = f'{get_absolute_path("ui_auto")}\\testcase\\testsuits\\reports.zip'
        zip_dir(file_path, zip_path)
        with open(zip_path, 'rb') as f:
            attach = MIMEBase('application', 'octet-stream')
            attach.set_payload(f.read())
            attach.add_header('Content-Disposition',
                              'attachment',
                              filename='Report.zip')
            encoders.encode_base64(attach)
            f.close()
        msg.attach(attach)

        server = smtplib.SMTP(mail_server, port)
        server.login(sender_email, sender_password)
        server.sendmail(sender_email, receive_email, msg.as_string())
        server.quit()
        print('邮件已发送')
    except BaseException as e:
        print(e)
Esempio n. 16
0
        assert (self.device.GetPin(self.LED2).toChar() == "H")
        self.doRun(2500000)  # 25ms
        assert (self.device.GetPin(self.LED1).toChar() == "H")
        assert (self.device.GetPin(self.LED2).toChar() == "H")
        self.doRun(2500000)  # 25ms
        assert (self.device.GetPin(self.LED1).toChar() == "H")
        assert (self.device.GetPin(self.LED2).toChar() == "H")
        # Deuxieme seconde
        self.doRun(2500000)  # 25ms
        assert (self.device.GetPin(self.LED1).toChar() == "L")
        assert (self.device.GetPin(self.LED2).toChar() == "H")
        self.doRun(2500000)  # 25ms
        assert (self.device.GetPin(self.LED1).toChar() == "L")
        assert (self.device.GetPin(self.LED2).toChar() == "H")
        self.doRun(2500000)  # 25ms
        assert (self.device.GetPin(self.LED1).toChar() == "L")
        assert (self.device.GetPin(self.LED2).toChar() == "H")
        self.doRun(2500000)  # 25ms
        assert (self.device.GetPin(self.LED1).toChar() == "L")
        assert (self.device.GetPin(self.LED2).toChar() == "H")
        self.doRun(2500000)  # 25ms
        assert (self.device.GetPin(self.LED1).toChar() == "L")
        assert (self.device.GetPin(self.LED2).toChar() == "L")


if __name__ == "__main__":
    allTestsFrom = defaultTestLoader.loadTestsFromTestCase
    suite = TestSuite()
    suite.addTests(allTestsFrom(TestEx1Semaine2))
    TextTestRunner(verbosity=2).run(suite)
Esempio n. 17
0
        """Stop web driver"""
        self.driver.quit()

    def test_case_1(self):
        """Opening Browser and navigating to search engine"""
        try:
            self.driver.get('https://duckduckgo.com')
            search_form = self.driver.find_element_by_id(
                'search_form_input_homepage')
            search_form.send_keys('real python')
            search_form.submit()
            results = self.driver.find_elements_by_class_name('result')
            print(results[0].text)

        except NoSuchElementException as ex:
            self.fail(ex.msg)


if __name__ == '__main__':
    # create the suite from the test classes
    suite = TestSuite()
    # load the tests
    tests = unittest.TestLoader()

    # add the tests to the suite
    suite.addTests(tests.loadTestsFromTestCase(duckduckgo))

    # run the suite
    runner = unittest.TextTestRunner()
    runner.run(suite)
from unittest import TextTestRunner
from unittest.suite import TestSuite
from unittest.loader import TestLoader
from test_case_06 import TestCase06

if __name__ == "__main__":
    suite = TestSuite()
    loader = TestLoader()
    suite.addTests(loader.loadTestsFromTestCase(TestCase06))

    # run the suite
    debug_enabled = False
    if debug_enabled:
        """
        NOTE Using buffer=False and failfast=True together ensures that any exception occurring during test runs is printed
        to stderr immediately instead of being hold back until all test cases finished.
        However at least failfast has to be disabled if test cases contain tests that are expected to fail.
        """
        failfast = True
        buffer = False
    else:
        failfast = False
        buffer = True
    runner = TextTestRunner(failfast=failfast, buffer=buffer, verbosity=2)
    runner.run(suite)

Esempio n. 19
0
# This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API.
#
# Copyright (C) 2021 Alban 'spl0k' Féron
#
# Distributed under terms of the GNU AGPLv3 license.

import importlib
import os
import os.path
import unittest

from unittest.suite import TestSuite


def load_tests(loader, tests, pattern):
    # Skip these tests from discovery
    return tests


suite = TestSuite()
for e in os.scandir(os.path.dirname(__file__)):
    if not e.name.startswith("test") or not e.name.endswith(".py"):
        continue

    module = importlib.import_module("tests.net." + e.name[:-3])
    tests = unittest.defaultTestLoader.loadTestsFromModule(module)
    suite.addTests(tests)
Esempio n. 20
0
def load_tests(loader, tests, pattern):
    suite = TestSuite()
    for test_module in test_cases:
        tests = loader.loadTestsFromModule(test_module)
        suite.addTests(tests)
    return suite
Esempio n. 21
0
from interface.K12edu.testcase.addHomework_loop import AddHomeworkLoop
from interface.K12edu.testcase.student_homework_controller import DoHomework
from interface.K12edu.testcase.submit_work import SubmitWork

project_cwd = get_absolute_path('testcase')
report_path = project_cwd.joinpath(
    f'testsuits\\reports\\{time.strftime("%Y%m%d%H%M%S")}.html').as_posix()
fp = open(report_path, 'wb')
suite = TestSuite()
test_01 = TestUser('test_login_01')
test_02 = TestGetClassList('test_01')
test_03 = TestAddCourse('test_01')
test_04 = AddHomework('test_01')
test_05 = DoHomework('test_do_homework_01')
test_06 = AddHomework('test_02')
test_07 = DoHomework('test_do_homework_02')
test_08 = AddHomeworkLoop('test_01')
test_09 = AddHomeworkLoop('test_02')
test_10 = SubmitWork('test_01')
test_11 = SubmitWork('test_02')
test_12 = SubmitWork('test_03')

suite.addTests([
    test_01, test_02, test_03, test_04, test_05, test_06, test_07, test_08,
    test_09, test_10, test_11, test_12
])
runner = HTMLTestRunner(stream=fp,
                        title='叮当码教育版2期接口自动化测试报告',
                        description='登录发布课程、作业')
runner.run(suite)
import os
import time
from interface.base.HTMLTestRunner import HTMLTestRunner
from unittest.suite import TestSuite
from interface.uni_lab.testcase.login import TestLogin
from interface.uni_lab.testcase.getClassList import TestGetClassList
from interface.uni_lab.testcase.addCourse import TestAddCourse
from interface.uni_lab.testcase.addHomework_loop import AddHomework_loop

project_path = os.path.dirname(os.getcwd())
print(project_path)
report_path = project_path + '\\reports' + time.strftime(
    '%Y%m%d%H%M%S') + '.html'
fp = open(report_path, 'wb')
suite = TestSuite()
test_01 = TestLogin('test_01')
test_02 = TestGetClassList('test_01')
test_03 = TestAddCourse('test_01')
test_04 = AddHomework_loop('test_addHomework')

suite.addTests([test_01, test_02, test_03, test_04])
runner = HTMLTestRunner(stream=fp,
                        title='叮当码教育版2期接口自动化测试报告',
                        description='登录发布课程、作业')
runner.run(suite)
Esempio n. 23
0
def load_tests(loader, tests, pattern):
    suite = TestSuite()
    for test_module in test_cases:
        tests = loader.loadTestsFromModule(test_module)
        suite.addTests(tests)
    return suite
Esempio n. 24
0
import unittest
from unittest.suite import TestSuite

from tests.test_1_compare_mobiles import TestOne
from tests.test_2_price_range import TestTwo

if __name__ == "__main__":

	# create the suite from the test classes
    suite = TestSuite()
    # load the tests
    tests = unittest.TestLoader()

	# add the tests to the suite
    suite.addTests(tests.loadTestsFromTestCase(TestOne))
    suite.addTests(tests.loadTestsFromTestCase(TestTwo))

    # run the suite
    runner = unittest.TextTestRunner()
    runner.run(suite)
Esempio n. 25
0
# %%
from test.test_dimension import TestClassDimension
from test.test_quantity import TestQuantity
from unittest.suite import TestSuite

# %%

# %%
# create the suite from the test classes
suite = TestSuite()
# load the tests
tests = unittest.TestLoader()

# add the tests to the suite
suite.addTests(tests.loadTestsFromTestCase(TestClassDimension))
suite.addTests(tests.loadTestsFromTestCase(TestQuantity))

# run the suite
runner = unittest.TextTestRunner()
runner.run(suite)

# %%
# !snakeviz prunsum_file

# %%
# %timeit 

# %%
# %prun -D prunsum_file -s nfl runner.run(suite)
Esempio n. 26
0
'''
Created on 15 aout 2013

@author: ju
'''

import unittest
from unittest.suite import TestSuite

if __name__ == '__main__':
    suite = TestSuite()
    loader = unittest.TestLoader()
    suite.addTests(loader.discover(start_dir="test", pattern="*test.py"))
    
    unittest.TextTestRunner(verbosity=1).run(suite)