You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

conftest.py 1.6 kB

5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. # Copyright 2020 Huawei Technologies Co., Ltd
  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 at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # 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 and
  13. # limitations under the License.
  14. # ============================================================================
  15. """
  16. @File : conftest.py
  17. @Desc : common fixtures for pytest
  18. """
  19. import pytest
  20. from _pytest.runner import runtestprotocol
  21. def pytest_addoption(parser):
  22. """
  23. add runmode option to control running testcase
  24. """
  25. parser.addoption(
  26. "--runmode", action="store", default="nosimu",
  27. help="simu:simulator backend & nosimu for no backend"
  28. )
  29. @pytest.fixture
  30. def test_with_simu(request):
  31. """
  32. run PyNative testcases when compiled with simulator
  33. """
  34. return request.config.getoption("--runmode") == "simu"
  35. # https://stackoverflow.com/questions/14121657/how-to-get-test-name-and-test-result-during-run-time-in-pytest
  36. def pytest_runtest_protocol(item, nextitem):
  37. reports = runtestprotocol(item, nextitem=nextitem)
  38. for report in reports:
  39. if report.when == 'call':
  40. print(f"\n{item.name} --- {report.outcome}")
  41. return True