CoolFace
Apppublic

chendl/compositional_test

sourceHugging Faceupdated 3y agoView on Hugging Face
1likes
conftest.py82 linesDownload Raw Back to transformers
1# Copyright 2020 The HuggingFace Team. All rights reserved.2#3# Licensed under the Apache License, Version 2.0 (the "License");4# you may not use this file except in compliance with the License.5# You may obtain a copy of the License at6#7#     http://www.apache.org/licenses/LICENSE-2.08#9# Unless required by applicable law or agreed to in writing, software10# distributed under the License is distributed on an "AS IS" BASIS,11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12# See the License for the specific language governing permissions and13# limitations under the License.14 15# tests directory-specific settings - this file is run automatically16# by pytest before any tests are run17 18import doctest19import sys20import warnings21from os.path import abspath, dirname, join22 23 24# allow having multiple repository checkouts and not needing to remember to rerun25# 'pip install -e .[dev]' when switching between checkouts and running tests.26git_repo_path = abspath(join(dirname(__file__), "src"))27sys.path.insert(1, git_repo_path)28 29# silence FutureWarning warnings in tests since often we can't act on them until30# they become normal warnings - i.e. the tests still need to test the current functionality31warnings.simplefilter(action="ignore", category=FutureWarning)32 33 34def pytest_configure(config):35    config.addinivalue_line(36        "markers", "is_pt_tf_cross_test: mark test to run only when PT and TF interactions are tested"37    )38    config.addinivalue_line(39        "markers", "is_pt_flax_cross_test: mark test to run only when PT and FLAX interactions are tested"40    )41    config.addinivalue_line(42        "markers", "is_pipeline_test: mark test to run only when pipelines are tested"43    )44    config.addinivalue_line("markers", "is_staging_test: mark test to run only in the staging environment")45    config.addinivalue_line("markers", "accelerate_tests: mark test that require accelerate")46 47 48def pytest_addoption(parser):49    from transformers.testing_utils import pytest_addoption_shared50 51    pytest_addoption_shared(parser)52 53 54def pytest_terminal_summary(terminalreporter):55    from transformers.testing_utils import pytest_terminal_summary_main56 57    make_reports = terminalreporter.config.getoption("--make-reports")58    if make_reports:59        pytest_terminal_summary_main(terminalreporter, id=make_reports)60 61 62def pytest_sessionfinish(session, exitstatus):63    # If no tests are collected, pytest exists with code 5, which makes the CI fail.64    if exitstatus == 5:65        session.exitstatus = 066 67 68# Doctest custom flag to ignore output.69IGNORE_RESULT = doctest.register_optionflag('IGNORE_RESULT')70 71OutputChecker = doctest.OutputChecker72 73 74class CustomOutputChecker(OutputChecker):75    def check_output(self, want, got, optionflags):76        if IGNORE_RESULT & optionflags:77            return True78        return OutputChecker.check_output(self, want, got, optionflags)79 80 81doctest.OutputChecker = CustomOutputChecker82