File: pytest11.py

package info (click to toggle)
dials-data 2.4.0-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 892 kB
  • sloc: python: 647; makefile: 25
file content (41 lines) | stat: -rw-r--r-- 1,050 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
"""
pytest plugin functions
"""


from __future__ import annotations

import pytest

from .download import DataFetcher


def pytest_addoption(parser):
    parser.addoption(
        "--regression",
        action="store_true",
        default=False,
        help="run regression tests. Download data for those tests if required",
    )


@pytest.fixture(scope="session")
def dials_data(request) -> DataFetcher:
    """
    Return the location of a regression dataset as py.path object.
    Download the files if they are not on disk already.
    Skip the test if the dataset can not be downloaded.
    """
    if not request.config.getoption("--regression"):
        pytest.skip("Test requires --regression option to run.")
    df = DataFetcher()

    def fail_test_if_lookup_failed(result):
        if not result:
            pytest.fail(
                "Test data could not be downloaded. Your version of dials.data may be out of date"
            )
        return result

    setattr(df, "result_filter", fail_test_if_lookup_failed)
    return df