diff --git a/integration_tests/conftest.py b/integration_tests/conftest.py index 9fc5ef4..72dfe3f 100644 --- a/integration_tests/conftest.py +++ b/integration_tests/conftest.py @@ -1,4 +1,4 @@ -# Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. +# Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. # SPDX-License-Identifier: Apache-2.0 import pytest @@ -6,6 +6,9 @@ import pytest PROFILE_CI = "ci" PROFILE_DEVEL = "devel" +WORKSPACE = "workspace" +CRATE = "crate" + def pytest_addoption(parser): parser.addoption( @@ -26,6 +29,16 @@ def pytest_addoption(parser): "removed." ) + parser.addoption( + "--test-scope", + default=WORKSPACE, + choices=[WORKSPACE, CRATE], + help="Defines the scope of running tests: {} or {}".format( + WORKSPACE, + CRATE + ) + ) + @pytest.fixture def profile(request): @@ -37,7 +50,16 @@ def no_cleanup(request): return request.config.getoption("--no-cleanup") +@pytest.fixture +def test_scope(request): + return request.config.getoption("--test-scope") + + # This is used for defining global variables in pytest. def pytest_configure(): + # These constants are needed in tests, so this is the way that we can + # export them. pytest.profile_ci = PROFILE_CI pytest.profile_devel = PROFILE_DEVEL + pytest.workspace = WORKSPACE + pytest.crate = CRATE diff --git a/integration_tests/test_coverage.py b/integration_tests/test_coverage.py index 37217aa..1b815be 100644 --- a/integration_tests/test_coverage.py +++ b/integration_tests/test_coverage.py @@ -1,4 +1,4 @@ -# Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. +# Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. # SPDX-License-Identifier: Apache-2.0 """Test the coverage and update the threshold when coverage is increased.""" @@ -63,7 +63,7 @@ def _write_coverage_config(coverage_config): json.dump(coverage_config, outfile) -def _get_current_coverage(coverage_config, no_cleanup): +def _get_current_coverage(coverage_config, no_cleanup, test_scope): """Helper function that returns the coverage computed with kcov.""" kcov_output_dir = os.path.join(REPO_ROOT_PATH, "kcov_output") @@ -89,11 +89,15 @@ def _get_current_coverage(coverage_config, no_cleanup): exclude_pattern += ',' + additional_exclude_path additional_kcov_param = '' + + if test_scope == pytest.workspace: + additional_kcov_param += '--all ' + crate_features = coverage_config["crate_features"] if crate_features: additional_kcov_param += '--features=' + crate_features - kcov_cmd = "CARGO_TARGET_DIR={} cargo kcov {} --all " \ + kcov_cmd = "CARGO_TARGET_DIR={} cargo kcov {} " \ "--output {} -- " \ "--exclude-region={} " \ "--exclude-pattern={} " \ @@ -127,15 +131,15 @@ def _get_current_coverage(coverage_config, no_cleanup): return coverage -def test_coverage(profile, no_cleanup): +def test_coverage(profile, no_cleanup, test_scope): coverage_config = _read_test_config() - current_coverage = _get_current_coverage(coverage_config, no_cleanup) + current_coverage = _get_current_coverage(coverage_config, no_cleanup, test_scope) previous_coverage = coverage_config["coverage_score"] if previous_coverage < current_coverage: if profile == pytest.profile_ci: # In the CI Profile we expect the coverage to be manually updated. - assert False,\ - "Coverage is increased from {} to {}. "\ + assert False, \ + "Coverage is increased from {} to {}. " \ "Please update the coverage in coverage_config_{}.json."\ .format( previous_coverage,