Example #1
0
def test_env_vars_set(testdir, undecorated_test_function, testsuite_attribs_exp, simple_test_config):
    """Verify that pytest accepts our fixture with all relevant environment variables set."""

    # Setup
    testdir.makepyfile(undecorated_test_function.format(test_name='test_pass'))

    for env in ASC_TEST_ENV_VARS:
        os.environ[env] = env

    args = ["--pytest-zigzag-config", simple_test_config]
    junit_xml = run_and_parse(testdir, 0, args)[0]

    # Test
    assert is_sub_dict(testsuite_attribs_exp, junit_xml.testsuite_attribs)

    expected = {env: env for env in ASC_TEST_ENV_VARS}

    props = junit_xml.testsuite_props
    missingx = []
    missingy = []
    for x in expected:
        if x not in props:
            missingx.append(x)
    for y in props:
        if y not in expected:
            missingy.append(y)

    assert junit_xml.testsuite_props == expected
Example #2
0
def test_no_env_vars_set(testdir, undecorated_test_function, testsuite_attribs_exp):
    """Verify that pytest accepts our fixture without setting any environment variables."""

    # Setup
    testdir.makepyfile(undecorated_test_function.format(test_name='test_pass'))

    junit_xml = run_and_parse(testdir)

    # Test
    assert is_sub_dict(testsuite_attribs_exp, junit_xml.testsuite_attribs)

    for env_var in ASC_ENV_VARS:
        assert junit_xml.testsuite_props[env_var] == 'Unknown'
Example #3
0
def test_no_env_vars_set(testdir, undecorated_test_function, testsuite_attribs_exp, simple_test_config):
    """Verify that pytest accepts our fixture without setting any environment variables."""

    # Setup
    testdir.makepyfile(undecorated_test_function.format(test_name='test_pass'))

    args = ["--pytest-zigzag-config", simple_test_config]
    junit_xml = run_and_parse(testdir, 0, args)[0]

    # Test
    assert is_sub_dict(testsuite_attribs_exp, junit_xml.testsuite_attribs)

    for env_var in ASC_TEST_ENV_VARS:
        assert junit_xml.testsuite_props[env_var] == 'None' or '[]'
Example #4
0
def test_env_vars_set(testdir, undecorated_test_function, testsuite_attribs_exp):
    """Verify that pytest accepts our fixture with all relevant environment variables set."""

    # Setup
    testdir.makepyfile(undecorated_test_function.format(test_name='test_pass'))

    for env in ASC_ENV_VARS:
        os.environ[env] = env

    junit_xml = run_and_parse(testdir)

    # Test
    assert is_sub_dict(testsuite_attribs_exp, junit_xml.testsuite_attribs)

    expected = {env: env for env in ASC_ENV_VARS}
    expected['ci-environment'] = 'asc'  # This is not supplied by the environment
    assert junit_xml.testsuite_props == expected
Example #5
0
def test_class_with_setup_and_teardown_steps(
        testdir, properly_decorated_test_class_with_step_failure,
        simple_test_config):
    """Verify that steps with 'setup' or 'teardown' in the name will always be ran regardless if previous steps failed.
    """

    # Expect
    test_steps = {
        'test_step_one': 'test_setup',
        'test_step_two': 'test_fail',
        'test_step_three': 'test_skip',
        'test_step_four': 'test_teardown'
    }
    tc_props_exps = {
        'test_name': 'TestCaseWithSteps',
        'test_id': 'test_case_class_id',
        'jira_id': 'ASC-123'
    }
    ts_attribs_exps = {
        'tests': '4',
        'errors': '0',
        'skips': '1',
        'failures': '1'
    }
    # Setup
    testdir.makepyfile(
        properly_decorated_test_class_with_step_failure.format(
            **merge_dicts(test_steps, tc_props_exps)))

    args = ["--pytest-zigzag-config", simple_test_config]
    junit_xml = run_and_parse(testdir, 1, args)[0]

    # Test
    assert is_sub_dict(ts_attribs_exps, junit_xml.testsuite_attribs)

    for test_step in test_steps.values():
        assert junit_xml.get_testcase_properties(
            test_step)['test_step'] == 'true'
        assert junit_xml.get_testcase_properties(
            test_step)['test_id'] == tc_props_exps['test_id']
        assert junit_xml.get_testcase_properties(
            test_step)['jira'] == tc_props_exps['jira_id']
Example #6
0
def test_class_with_failed_step(
        testdir, properly_decorated_test_class_with_step_failure,
        simple_test_config):
    """Verify that steps that follow a failing step will automatically skip."""

    # Expect
    test_steps = {
        'test_step_one': 'test_step_one',
        'test_step_two': 'test_step_fail',
        'test_step_three': 'test_step_skip',
        'test_step_four': 'test_step_skip_again'
    }
    tc_props_exps = {
        'test_name': 'TestCaseWithSteps',
        'test_id': 'test_case_class_id',
        'jira_id': 'ASC-123'
    }
    ts_attribs_exps = {
        'tests': '4',
        'errors': '0',
        'skips': '2',
        'failures': '1'
    }
    # Setup
    testdir.makepyfile(
        properly_decorated_test_class_with_step_failure.format(
            **merge_dicts(test_steps, tc_props_exps)))

    args = ["--pytest-zigzag-config", simple_test_config]
    junit_xml = run_and_parse(testdir, 1, args)[0]

    # Test
    assert is_sub_dict(ts_attribs_exps, junit_xml.testsuite_attribs)

    for test_step in test_steps.values():
        assert junit_xml.get_testcase_properties(
            test_step)['test_step'] == 'true'
        assert junit_xml.get_testcase_properties(
            test_step)['test_id'] == tc_props_exps['test_id']
        assert junit_xml.get_testcase_properties(
            test_step)['jira'] == tc_props_exps['jira_id']