|
| 1 | +# Copyright 2018-2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"). You |
| 4 | +# may not use this file except in compliance with the License. A copy of |
| 5 | +# the License is located at |
| 6 | +# |
| 7 | +# http://aws.amazon.com/apache2.0/ |
| 8 | +# |
| 9 | +# or in the "license" file accompanying this file. This file is |
| 10 | +# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF |
| 11 | +# ANY KIND, either express or implied. See the License for the specific |
| 12 | +# language governing permissions and limitations under the License. |
| 13 | +from __future__ import absolute_import |
| 14 | + |
| 15 | +import logging |
| 16 | +import os |
| 17 | +import sys |
| 18 | + |
| 19 | +import pytest |
| 20 | + |
| 21 | +logger = logging.getLogger(__name__) |
| 22 | + |
| 23 | + |
| 24 | +dir_path = os.path.dirname(os.path.realpath(__file__)) |
| 25 | + |
| 26 | + |
| 27 | +def pytest_addoption(parser): |
| 28 | + parser.addoption("--build-image", "-D", action="store_true") |
| 29 | + parser.addoption("--build-base-image", "-B", action="store_true") |
| 30 | + parser.addoption("--aws-id") |
| 31 | + parser.addoption("--instance-type") |
| 32 | + parser.addoption("--docker-base-name", default="pytorch") |
| 33 | + parser.addoption("--region", default="us-west-2") |
| 34 | + parser.addoption("--framework-version", default="") |
| 35 | + parser.addoption( |
| 36 | + "--py-version", |
| 37 | + choices=["312"], |
| 38 | + default=str(sys.version_info.major), |
| 39 | + ) |
| 40 | + parser.addoption("--processor", choices=["gpu"], default="gpu") |
| 41 | + # If not specified, will default to {framework-version}-{processor}-py{py-version} |
| 42 | + parser.addoption("--tag", default=None) |
| 43 | + parser.addoption( |
| 44 | + "--generate-coverage-doc", |
| 45 | + default=False, |
| 46 | + action="store_true", |
| 47 | + help="use this option to generate test coverage doc", |
| 48 | + ) |
| 49 | + parser.addoption( |
| 50 | + "--efa", |
| 51 | + action="store_true", |
| 52 | + default=False, |
| 53 | + help="Run only efa tests", |
| 54 | + ) |
| 55 | + parser.addoption("--sagemaker-regions", default="us-west-2") |
| 56 | + |
| 57 | + |
| 58 | +def pytest_configure(config): |
| 59 | + config.addinivalue_line("markers", "efa(): explicitly mark to run efa tests") |
| 60 | + |
| 61 | + |
| 62 | +def pytest_runtest_setup(item): |
| 63 | + efa_tests = [mark for mark in item.iter_markers(name="efa")] |
| 64 | + if item.config.getoption("--efa") and not efa_tests: |
| 65 | + pytest.skip("Skipping non-efa tests due to --efa flag") |
| 66 | + elif not item.config.getoption("--efa") and efa_tests: |
| 67 | + pytest.skip("Skipping efa tests because --efa flag is missing") |
| 68 | + |
| 69 | + |
| 70 | +def pytest_collection_modifyitems(session, config, items): |
| 71 | + for item in items: |
| 72 | + print(f"item {item}") |
| 73 | + for marker in item.iter_markers(name="team"): |
| 74 | + print(f"item {marker}") |
| 75 | + team_name = marker.args[0] |
| 76 | + item.user_properties.append(("team_marker", team_name)) |
| 77 | + print(f"item.user_properties {item.user_properties}") |
| 78 | + |
| 79 | + if config.getoption("--generate-coverage-doc"): |
| 80 | + from test.test_utils.test_reporting import TestReportGenerator |
| 81 | + |
| 82 | + report_generator = TestReportGenerator(items, is_sagemaker=True) |
| 83 | + report_generator.generate_coverage_doc(framework="pytorch", job_type="training") |
0 commit comments