Example #1
0
def allure_report(request, tmpdir_factory):
    module = request.module.__file__
    tmpdir = tmpdir_factory.mktemp('data')
    _runner(tmpdir.strpath, module)
    with open("debug-runner", "a") as debugfile:
        print(tmpdir.strpath, file=debugfile)
    return AllureReport(tmpdir.strpath)
Example #2
0
class CaseStatus(unittest.TestCase):
    allure_report = AllureReport(os.path.join('output'))

    def test_tags(self):
        assert_that(
            self.allure_report,
            has_test_case(
                'Case With Tags',
                has_tag('my_awesome_tag'),
                has_tag('another_awesome_tag')
            )
        )

    def test_threads(self):
        assert_that(
            self.allure_report,
            has_test_case(
                'Case With Thread #0',
                has_label('thread', 'Thread #0')
            ),
            has_test_case(
                'Case With Thread #1',
                has_label('thread', 'Thread #1')
            )
        )

    def test_history_id(self):
        assert_that(
            self.allure_report,
            has_test_case(
                'Case With Tags',
                has_history_id()
            )
        )
Example #3
0
 def run_with_allure(self):
     logger = AllureFileLogger(self.testdir.tmpdir.strpath)
     with fake_logger("allure_pytest_bdd.plugin.AllureFileLogger", logger):
         self.testdir.runpytest("-s", "-v", "--alluredir", self.testdir.tmpdir)
         # print(a.stdout.lines)
         # print(a.stderr.lines)
         self.allure_report = AllureReport(self.testdir.tmpdir.strpath)
Example #4
0
class StepStatus(unittest.TestCase):
    allure_report = AllureReport(os.path.join('output'))

    def test_passed_with_step(self):
        assert_that(
            self.allure_report,
            has_test_case(
                'Passed Case With Step', with_status('passed'),
                has_step(RobotBasicKeywords.NO_OPERATION,
                         with_status('passed'))))

    def test_passed_with_multiple_step(self):
        assert_that(
            self.allure_report,
            has_test_case(
                'Passed Case With Multiple Step',
                with_status('passed'),
                has_step(
                    'Passed Keyword 1', with_status('passed'),
                    has_step(RobotBasicKeywords.NO_OPERATION,
                             with_status('passed'))),
                has_step(
                    'Passed Keyword 2', with_status('passed'),
                    has_step(RobotBasicKeywords.NO_OPERATION,
                             with_status('passed'))),
            ))
Example #5
0
def run_robot_with_allure(*args, **kwargs):
    root = os.path.abspath(os.path.join(__file__, "..", ".."))
    targets = map(lambda target: os.path.join(root, target), args)
    tmp_path = mkdtemp(dir=os.environ.get('TEST_TMP', '/tmp'))

    def run_robot(path, **kw):

        # ToDo: fix it (_core not works correctly with multiprocessing)
        # import six
        # import allure_commons
        # if six.PY2:
        #     reload(allure_commons._core)
        # else:
        #     import importlib
        #     importlib.reload(allure_commons._core)
        #
        #

        from allure_robotframework import allure_robotframework

        listener = allure_robotframework(logger_path=tmp_path)
        stdout_file = os.path.abspath(os.path.join(tmp_path, "..", "stdout.txt"))
        output_path = os.path.abspath(os.path.join(tmp_path, ".."))

        with open(stdout_file, 'w+') as stdout:
            options = {"listener": listener, "outputdir": output_path, "stdout": stdout, "extension": "rst"}
            options.update(kw)
            run(path, **options)

    robot_process = Process(target=run_robot, args=targets, kwargs=kwargs)
    robot_process.start()
    robot_process.join()

    return AllureReport(tmp_path)
Example #6
0
def robot_run_with_allure(work_dir, *args, **kwargs):
    allure_dir = os.path.join(work_dir, 'allure')

    output_dir = os.path.join(work_dir, 'output')
    os.mkdir(output_dir)

    stdout_file = os.path.join(output_dir, 'stdout.txt')

    def target(*a, **kw):

        # ToDo: fix it (_core not works correctly with multiprocessing)
        import six
        import allure_commons
        if six.PY2:
            reload(allure_commons._core)
        else:
            import importlib
            importlib.reload(allure_commons._core)

        listener = allure_robotframework(logger_path=allure_dir)

        with open(stdout_file, 'w+') as stdout:
            options = {
                "listener": listener,
                "outputdir": output_dir,
                "stdout": stdout
            }
            options.update(kw)
            run(*a, **options)

    robot_process = Process(target=target, args=args, kwargs=kwargs)
    robot_process.start()
    robot_process.join()

    return AllureReport(allure_dir)
Example #7
0
class CaseMetadata(unittest.TestCase):
    allure_report = AllureReport(os.environ.get('TEST_TMP', None))

    def test_tags(self):
        assert_that(
            self.allure_report,
            has_test_case(
                'Case In Suite With Metadata',
                has_link('https://google.com', LinkType.LINK, 'Link')))
Example #8
0
class CaseMetadata(unittest.TestCase):
    allure_report = AllureReport(os.path.join('output'))

    def test_tags(self):
        assert_that(
            self.allure_report,
            has_test_case(
                'Case In Suite With Metadata',
                has_link('https://google.com', LinkType.LINK, 'Link')
            )
        )
Example #9
0
    def run_with_params(*params):
        key = '{module}{param}'.format(module=module, param=''.join(params))
        if not request.config.cache.get(key, False):
            _runner(tmpdir.strpath, module, *params)
            request.config.cache.set(key, True)

            def clear_cache():
                request.config.cache.set(key, False)
            request.addfinalizer(clear_cache)

        return AllureReport(tmpdir.strpath)
Example #10
0
    def run_with_allure(self, *args, **kwargs):
        if self.request.node.get_closest_marker("real_logger"):
            self.testdir.runpytest("--alluredir", self.testdir.tmpdir, *args,
                                   **kwargs)
            self.allure_report = AllureReport(self.testdir.tmpdir.strpath)
        else:
            self.allure_report = AllureMemoryLogger()
            with fake_logger("allure_pytest.plugin.AllureFileLogger",
                             self.allure_report):
                self.testdir.runpytest("--alluredir", self.testdir.tmpdir,
                                       *args, **kwargs)

        return self.allure_report
Example #11
0
    def run_with_params(*params, **kwargs):
        cache = kwargs.get("cache", True)
        key = _get_hash('{thread}{module}{param}'.format(thread=thread_tag(), module=module, param=''.join(params)))
        if not request.config.cache.get(key, False):
            _runner(tmpdir.strpath, module, *params)
            if cache:
                request.config.cache.set(key, True)

                def clear_cache():
                    request.config.cache.set(key, False)
                request.addfinalizer(clear_cache)

        return AllureReport(tmpdir.strpath)
Example #12
0
class CaseStatus(unittest.TestCase):
    allure_report = AllureReport(os.environ.get('TEST_TMP', None))

    def test_one_step(self):
        assert_that(
            self.allure_report,
            has_test_case(
                'One Step',
                has_step_with_keyword_log(RobotBasicKeywords.NO_OPERATION)))

    def test_several_steps(self):
        assert_that(
            self.allure_report,
            has_test_case(
                'Several Steps',
                all_of(
                    has_step_with_keyword_log(
                        RobotBasicKeywords.LOG,
                        has_parameter('arg1', 'First Step')),
                    has_step_with_keyword_log(
                        RobotBasicKeywords.LOG,
                        has_parameter('arg1', 'Second Step')),
                    has_step_with_keyword_log(
                        RobotBasicKeywords.LOG,
                        has_parameter('arg1', 'Third Step')),
                )))

    def test_different_status_steps(self):
        assert_that(
            self.allure_report,
            has_test_case(
                'Different Status Steps',
                all_of(
                    has_step_with_keyword_log(RobotBasicKeywords.NO_OPERATION,
                                              with_status('passed')),
                    has_step_with_keyword_log(RobotBasicKeywords.FAIL,
                                              with_status('failed')))))

    def test_embedded_steps(self):
        assert_that(
            self.allure_report,
            has_test_case(
                'Embedded Steps',
                has_step_with_keyword_log(
                    'First Step',
                    has_step_with_keyword_log(
                        'Second Step',
                        has_step_with_keyword_log(
                            'Third Step',
                            has_step_with_keyword_log(
                                RobotBasicKeywords.NO_OPERATION))))))
Example #13
0
class TestSuites(unittest.TestCase):
    allure_report = AllureReport(os.environ.get('TEST_TMP', None))

    def test_case_with_description(self):
        assert_that(
            self.allure_report,
            has_test_case('Case With Description',
                          has_description('Case description')))

    def test_case_with_dynamyc_description(self):
        assert_that(
            self.allure_report,
            has_test_case('Case With Dynamic Description',
                          has_description('End description')))
def run_robot_with_allure(*args, **kwargs):
    root = os.path.abspath(os.path.join(__file__, "..", ".."))
    targets = map(lambda target: os.path.join(root, target), args)
    tmp_path = mkdtemp(dir=os.environ.get('TEST_TMP', '/tmp'))

    if "testplan" in kwargs:
        # kwargs.pop("testplan")
        kwargs["prerunmodifier"] = "allure_robotframework.testplan"
        file, filename = mkstemp(suffix=".json", dir=tmp_path)
        os.environ["ALLURE_TESTPLAN_PATH"] = filename
        with os.fdopen(file, 'w') as tmp:
            tmp.write(kwargs["testplan"])

    def run_robot(path, **kw):

        # ToDo: fix it (_core not works correctly with multiprocessing)
        # import six
        # import allure_commons
        # if six.PY2:
        #     reload(allure_commons._core)
        # else:
        #     import importlib
        #     importlib.reload(allure_commons._core)
        #
        #

        from allure_robotframework import allure_robotframework

        listener = allure_robotframework(logger_path=tmp_path)
        stdout_file = os.path.abspath(
            os.path.join(tmp_path, "..", "stdout.txt"))
        output_path = os.path.abspath(os.path.join(tmp_path, ".."))

        with open(stdout_file, 'w+') as stdout:
            options = {
                "listener": listener,
                "outputdir": output_path,
                "stdout": stdout,
                "extension": "rst"
            }
            options.update(kw)
            run(path, **options)

    robot_process = Process(target=run_robot, args=targets, kwargs=kwargs)
    robot_process.start()
    robot_process.join()

    os.environ.pop("ALLURE_TESTPLAN_PATH", None)

    return AllureReport(tmp_path)
Example #15
0
class TestSuites(unittest.TestCase):
    allure_report = AllureReport(os.path.join('output'))

    def test_case_with_description(self):
        assert_that(
            self.allure_report,
            has_test_case('Case With Description',
                          has_description('Case description')))

    def test_case_with_dynamyc_description(self):
        assert_that(
            self.allure_report,
            has_test_case('Case With Dynamic Description',
                          has_description('End description')))
Example #16
0
    def run(context, **kwargs):
        cmd_args = '-v -f allure_behave.formatter:AllureFormatter -f pretty'
        cmd = '{options} {cmd}'.format(cmd=cmd_args,
                                       options=kwargs.get('args', ''))
        config = Configuration(command_args=cmd)

        result_tmp_dir = mkdtemp(dir=os.environ.get('TEST_TMP', None))
        stream_opener = StreamOpener(filename=result_tmp_dir)

        model_runner = ModelRunner(config, [context.feature_definition])
        model_runner.formatters = make_formatters(config, [stream_opener])
        model_runner.run()

        context.allure_report = AllureReport(result_tmp_dir)
Example #17
0
def run_behave_with_allure(context, **kwargs):
    with test_context():
        cmd_args = '-f allure_behave.formatter:AllureFormatter'
        cmd = '{options} {cmd}'.format(cmd=cmd_args,
                                       options=kwargs.get('args', ''))
        config = Configuration(command_args=cmd)
        result_tmp_dir = mkdtemp(dir=os.environ.get('TEST_TMP', None))
        stream_opener = StreamOpener(filename=result_tmp_dir)
        model_runner = ModelRunner(config, context.feature_definition)
        model_runner.formatters = make_formatters(config, [stream_opener])
        model_runner.hooks = getattr(context, 'globals', dict())
        model_runner.run()
        context.allure_report = AllureReport(result_tmp_dir)

    os.environ.pop("ALLURE_TESTPLAN_PATH", None)
Example #18
0
class CaseStatus(unittest.TestCase):
    allure_report = AllureReport(os.environ.get('TEST_TMP', None))

    def test_passed(self):
        assert_that(self.allure_report, has_test_case('Passed Case', with_status('passed')))

    def test_failed(self):
        assert_that(self.allure_report, has_test_case('Failed Case', with_status('failed')))

    def test_failed_with_details(self):
        assert_that(self.allure_report, has_test_case('Failed Case With Message',
                                                      with_status('failed'),
                                                      has_status_details(with_message_contains('Failed Details')
                                                                         )
                                                      )
                    )
Example #19
0
class CaseStatus(unittest.TestCase):
    allure_report = AllureReport(os.path.join('output'))

    def test_passed(self):
        assert_that(self.allure_report,
                    has_test_case('Passed Case', with_status('passed')))

    def test_failed(self):
        assert_that(self.allure_report,
                    has_test_case('Failed Case', with_status('failed')))

    def test_failed_with_details(self):
        assert_that(
            self.allure_report,
            has_test_case(
                'Failed Case With Message', with_status('failed'),
                has_status_details(with_message_contains('Failed Details'))))
Example #20
0
def robot_run_with_allure(work_dir, *args, **kwargs):
    allure_dir = os.path.join(work_dir, 'allure')

    output_dir = os.path.join(work_dir, 'output')
    os.mkdir(output_dir)

    stdout_file = os.path.join(output_dir, 'stdout.txt')

    def target(*a, **kw):
        listener = allure_robotframework(logger_path=allure_dir)

        with open(stdout_file, 'w+') as stdout:
            options = {"listener": listener, "outputdir": output_dir, "stdout": stdout}
            options.update(kw)
            run(*a, **options)

    robot_process = Process(target=target, args=args, kwargs=kwargs)
    robot_process.start()
    robot_process.join()

    return AllureReport(allure_dir)
Example #21
0
def allure_report(request, tmpdir_factory):
    module = request.module.__file__
    tmpdir = tmpdir_factory.mktemp('data')
    _runner(tmpdir.strpath, module)
    return AllureReport(tmpdir.strpath)
Example #22
0
class TestSuites(unittest.TestCase):
    allure_report = AllureReport(os.environ.get('TEST_TMP', None))

    def test_case_with_setup(self):
        assert_that(
            self.allure_report,
            has_test_case(
                'Case With Test Setup',
                has_container(self.allure_report,
                              has_before('Test Setup Keyword'))),
        )

    def test_case_with_teardown(self):
        assert_that(
            self.allure_report,
            has_test_case(
                'Case With Test Teardown',
                has_container(self.allure_report,
                              has_after('Test Teardown Keyword'))),
        )

    def test_case_with_fixtures(self):
        assert_that(
            self.allure_report,
            has_test_case(
                'Case With Test Fixtures',
                has_container(
                    self.allure_report,
                    all_of(has_before('Test Setup Keyword'),
                           has_after('Test Teardown Keyword')))),
        )

    def test_group_without_test_fixtures(self):
        assert_that(
            self.allure_report,
            has_test_case(
                'Case Without Test Fixtures',
                has_container(
                    self.allure_report,
                    has_container(
                        self.allure_report,
                        all_of(has_before('Suite Setup Keyword'),
                               has_after('Suite Teardown Keyword'))))),
        )

    def test_group_with_test_setup(self):
        assert_that(
            self.allure_report,
            has_test_case(
                'Case With Test Setup',
                has_container(
                    self.allure_report,
                    has_container(
                        self.allure_report,
                        all_of(has_before('Suite Setup Keyword'),
                               has_after('Suite Teardown Keyword'))),
                    has_before('Test Setup Keyword'))),
        )

    def test_group_with_test_teardown(self):
        assert_that(
            self.allure_report,
            has_test_case(
                'Case With Test Teardown',
                has_container(
                    self.allure_report,
                    has_container(
                        self.allure_report,
                        all_of(has_before('Suite Setup Keyword'),
                               has_after('Suite Teardown Keyword'))),
                    has_after('Test Teardown Keyword'))),
        )

    def test_group_with_test_fixtures(self):
        assert_that(
            self.allure_report,
            has_test_case(
                'Case With Test Fixtures',
                has_container(
                    self.allure_report,
                    has_container(
                        self.allure_report,
                        all_of(has_before('Suite Setup Keyword'),
                               has_after('Suite Teardown Keyword'))),
                    all_of(has_before('Test Setup Keyword'),
                           has_after('Test Teardown Keyword')))),
        )
Example #23
0
class TestSuites(unittest.TestCase):
    allure_report = AllureReport(os.environ.get('TEST_TMP', None))

    def test_single_suite(self):
        assert_that(
            self.allure_report,
            has_test_case(
                'Case With Single Suite',
                has_container(
                    self.allure_report,
                    has_entry(
                        'name', 'Case With Single Suite'),
                    has_container(
                        self.allure_report,
                        has_entry(
                            'name', 'Single Suite'))
                ),
                has_suite('Single Suite')
            )
        )

    def test_double_suite(self):
        assert_that(
            self.allure_report,
            has_test_case(
                'Case With Two Parent Suites',
                has_container(
                    self.allure_report,
                    has_entry(
                        'name', 'Case With Two Parent Suites'),
                    has_container(
                        self.allure_report,
                        has_entry(
                            'name', 'Suite With One Parent'),
                        has_container(
                            self.allure_report,
                            has_entry('name', 'First Level Suite')
                        )
                    )
                ),
                has_sub_suite('Suite With One Parent'),
                has_suite('First Level Suite'),
            )
        )

    def test_triple_suite(self):
        assert_that(
            self.allure_report,
            has_test_case(
                'Case With Three Parent Suites',
                has_container(
                    self.allure_report,
                    has_entry(
                        'name', 'Case With Three Parent Suites'),
                    has_container(
                        self.allure_report,
                        has_entry(
                            'name', 'Suite With Two Parent'),
                        has_container(
                            self.allure_report,
                            has_entry(
                                'name', 'Second Level Suite'),
                            has_container(
                                self.allure_report,
                                has_entry('name', 'First Level Suite')
                            )
                        )
                    )
                ),
                has_sub_suite('Suite With Two Parent'),
                has_suite('Second Level Suite'),
                has_parent_suite('First Level Suite')
            )
        )

    def test_quadruple_suite(self):
        assert_that(
            self.allure_report,
            has_test_case(
                'Case With Four Parent Suites',
                has_container(
                    self.allure_report,
                    has_entry('name', 'Case With Four Parent Suites'),
                    has_container(
                        self.allure_report,
                        has_entry('name', 'Suite With Three Parent'),
                        has_container(
                            self.allure_report,
                            has_entry('name', 'Third Level Suite'),
                            has_container(
                                self.allure_report,
                                has_entry('name', 'Second Level Suite'),
                                has_container(
                                    self.allure_report,
                                    has_entry('name', 'First Level Suite')
                                )
                            )
                        )
                    )
                ),
                has_sub_suite('Third Level Suite.Suite With Three Parent'),
                has_suite('Second Level Suite'),
                has_parent_suite('First Level Suite')
            )
        )