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

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