Richard Burton | dc0c6ed | 2020-04-08 16:39:05 +0100 | [diff] [blame] | 1 | # Copyright © 2020 Arm Ltd. All rights reserved. |
| 2 | # SPDX-License-Identifier: MIT |
| 3 | import os |
| 4 | import platform |
| 5 | |
| 6 | import pytest |
| 7 | |
| 8 | ARCHITECTURES = set("x86_64 aarch64".split()) |
| 9 | |
| 10 | |
| 11 | @pytest.fixture(scope="module") |
| 12 | def data_folder_per_test(request): |
| 13 | """ |
| 14 | This fixture returns path to folder with test resources (one per test module) |
| 15 | """ |
| 16 | |
| 17 | basedir, script = request.fspath.dirname, request.fspath.basename |
| 18 | return str(os.path.join(basedir, "testdata", os.path.splitext(script)[0])) |
| 19 | |
| 20 | |
| 21 | @pytest.fixture(scope="module") |
| 22 | def shared_data_folder(request): |
| 23 | """ |
| 24 | This fixture returns path to folder with shared test resources among all tests |
| 25 | """ |
| 26 | |
| 27 | return str(os.path.join(request.fspath.dirname, "testdata", "shared")) |
| 28 | |
| 29 | |
| 30 | @pytest.fixture(scope="function") |
| 31 | def tmpdir(tmpdir): |
| 32 | """ |
| 33 | This fixture returns path to temp folder. Fixture was added for py35 compatibility |
| 34 | """ |
| 35 | |
| 36 | return str(tmpdir) |
| 37 | |
| 38 | |
| 39 | def pytest_runtest_setup(item): |
| 40 | supported_architectures = ARCHITECTURES.intersection(mark.name for mark in item.iter_markers()) |
| 41 | arch = platform.machine() |
| 42 | if supported_architectures and arch not in supported_architectures: |
| 43 | pytest.skip("cannot run on platform {}".format(arch)) |
| 44 | |
| 45 | |
| 46 | def pytest_configure(config): |
| 47 | config.addinivalue_line( |
| 48 | "markers", "aarch64: mark test to run only on aarch64" |
| 49 | ) |
| 50 | config.addinivalue_line( |
| 51 | "markers", "x86_64: mark test to run only on x86_64" |
| 52 | ) |