File: conftest.py

package info (click to toggle)
python-django-celery-results 2.6.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 696 kB
  • sloc: python: 2,373; makefile: 312; sh: 7; sql: 2
file content (38 lines) | stat: -rw-r--r-- 900 bytes parent folder | download | duplicates (4)
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
import pytest


def pytest_addoption(parser):
    parser.addoption(
        '-B',
        '--run-benchmarks',
        action='store_true',
        default=False,
        help='run benchmarks',
    )


def pytest_runtest_setup(item):
    """
    Skip tests marked benchmark unless --run-benchmark is given to pytest
    """
    run_benchmarks = item.config.getoption('--run-benchmarks')

    is_benchmark = any(item.iter_markers(name="benchmark"))

    if is_benchmark:
        if run_benchmarks:
            return

        pytest.skip(
            'need --run-benchmarks to run benchmarks'
        )


def pytest_collection_modifyitems(items):
    """
    Add the "benchmark" mark to tests that start with "benchmark_".
    """
    for item in items:
        test_class_name = item.cls.__name__
        if test_class_name.startswith("benchmark_"):
            item.add_marker(pytest.mark.benchmark)