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.8 kB

5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. parser.addoption(
  30. "--shard", action="store", default="0",
  31. help="shard id for parallel pipeline"
  32. )
  33. @pytest.fixture
  34. def test_with_simu(request):
  35. """
  36. run PyNative testcases when compiled with simulator
  37. """
  38. return request.config.getoption("--runmode") == "simu"
  39. @pytest.fixture
  40. def shard(request):
  41. """
  42. specify shard id for parallel pipeline testcases
  43. """
  44. return request.config.getoption("--shard")
  45. # https://stackoverflow.com/questions/14121657/how-to-get-test-name-and-test-result-during-run-time-in-pytest
  46. def pytest_runtest_protocol(item, nextitem):
  47. reports = runtestprotocol(item, nextitem=nextitem)
  48. for report in reports:
  49. if report.when == 'call':
  50. print(f"\n{item.name} --- {report.outcome}")
  51. return True