|
| 1 | +# Copyright (c) 2024 coldsofttech |
| 2 | +# |
| 3 | +# Permission is hereby granted, free of charge, to any person obtaining a copy |
| 4 | +# of this software and associated documentation files (the "Software"), to deal |
| 5 | +# in the Software without restriction, including without limitation the rights |
| 6 | +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 7 | +# copies of the Software, and to permit persons to whom the Software is |
| 8 | +# furnished to do so, subject to the following conditions: |
| 9 | +# |
| 10 | +# The above copyright notice and this permission notice shall be included in all |
| 11 | +# copies or substantial portions of the Software. |
| 12 | +# |
| 13 | +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 14 | +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 15 | +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 16 | +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 17 | +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 18 | +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 19 | +# SOFTWARE. |
| 20 | + |
| 21 | +def pytest_collection_modifyitems(config, items): |
| 22 | + """ |
| 23 | + Custom pytest hook to modify the collection of test items. |
| 24 | + This function sorts test items to execute specific tests first. |
| 25 | + """ |
| 26 | + def test_order(test_name): |
| 27 | + # Define the desired order of execution for specific test names |
| 28 | + order_mapping = { |
| 29 | + 'test_get_config_value_invalid_no_config_set': 1, |
| 30 | + 'test_valid_no_params': 2, |
| 31 | + 'test_invalid_exposed_permissions': 3, |
| 32 | + 'test_valid_insecure': 4, |
| 33 | + 'test_invalid_file_not_found': 5, |
| 34 | + 'test_invalid_json': 6, |
| 35 | + 'test_get_config_value_valid_string': 7, |
| 36 | + 'test_get_config_value_valid_integer': 8, |
| 37 | + 'test_get_config_value_valid_dict': 9, |
| 38 | + 'test_get_config_value_valid_boolean': 10, |
| 39 | + 'test_get_config_value_valid_list': 11, |
| 40 | + 'test_get_config_value_valid_audit_all': 12, |
| 41 | + 'test_get_config_value_valid_audit_specific': 13 |
| 42 | + } |
| 43 | + return order_mapping.get(test_name, float('inf')) # Default to infinity for tests not in the mapping |
| 44 | + |
| 45 | + items.sort(key=lambda item: (test_order(item.nodeid.split("::")[-1]), item.fspath, item.originalname)) |
0 commit comments