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 2.9 kB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. # Copyright 2019 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. """The st config."""
  16. import os
  17. import shutil
  18. import sys
  19. import tempfile
  20. import pytest
  21. from ....utils import mindspore
  22. from ....utils.mindspore.dataset.engine.serializer_deserializer import SERIALIZED_PIPELINE
  23. sys.modules['mindspore'] = mindspore
  24. BASE_SUMMARY_DIR = tempfile.NamedTemporaryFile(prefix='test_lineage_summary_dir_base_').name
  25. SUMMARY_DIR = os.path.join(BASE_SUMMARY_DIR, 'run1')
  26. SUMMARY_DIR_2 = os.path.join(BASE_SUMMARY_DIR, 'run2')
  27. SUMMARY_DIR_3 = os.path.join(BASE_SUMMARY_DIR, 'except_run')
  28. COLLECTION_MODULE = 'TestModelLineage'
  29. API_MODULE = 'TestModelApi'
  30. DATASET_GRAPH = SERIALIZED_PIPELINE
  31. def get_module_name(nodeid):
  32. """Get the module name from nodeid."""
  33. _, module_name, _ = nodeid.split("::")
  34. return module_name
  35. def pytest_collection_modifyitems(items):
  36. """Modify the execution order."""
  37. split_items = {
  38. COLLECTION_MODULE: [],
  39. API_MODULE: []
  40. }
  41. for item in items:
  42. module_name = get_module_name(item.nodeid)
  43. module_item = split_items.get(module_name)
  44. if module_item is not None:
  45. module_item.append(item)
  46. ordered_items = split_items.get(COLLECTION_MODULE)
  47. item_scenes = []
  48. for item in ordered_items:
  49. scenes = [
  50. marker for marker in item.own_markers
  51. if marker.name.startswith('scene')
  52. ]
  53. if scenes:
  54. scene_mark = scenes[0].args[0]
  55. else:
  56. scene_mark = 0
  57. item_scenes.append((item, scene_mark))
  58. sorted_item_scenes = sorted(item_scenes, key=lambda x: x[1])
  59. ordered_items = [item_scene[0] for item_scene in sorted_item_scenes]
  60. ordered_items.extend(split_items.get(API_MODULE))
  61. items[:] = ordered_items
  62. @pytest.fixture(scope="session")
  63. def create_summary_dir():
  64. """Create summary directory."""
  65. try:
  66. if os.path.exists(BASE_SUMMARY_DIR):
  67. shutil.rmtree(BASE_SUMMARY_DIR)
  68. permissions = os.R_OK | os.W_OK | os.X_OK
  69. mode = permissions << 6
  70. if not os.path.exists(BASE_SUMMARY_DIR):
  71. os.mkdir(BASE_SUMMARY_DIR, mode=mode)
  72. yield
  73. finally:
  74. if os.path.exists(BASE_SUMMARY_DIR):
  75. shutil.rmtree(BASE_SUMMARY_DIR)