1#!/usr/bin/env python
2# coding=utf-8
3
4import pytest
5import bob.extension
6
7
8def pytest_configure(config):
9 """This function is run once for pytest setup"""
10
11 config.addinivalue_line(
12 "markers",
13 "skip_if_rc_var_not_set(name): this mark skips the test if a certain "
14 "~/.bobrc variable is not set",
15 )
16
17
18 config.addinivalue_line("markers", "slow: this mark indicates slow tests")
19
20
21def pytest_runtest_setup(item):
22 """This function is run for every test candidate in this directory
23
24 The test is run if this function returns ``None``. To skip a test, call
25 ``pytest.skip()``, specifying a reason.
26 """
27
28 # iterates over all markers for the item being examined, get the first
29 # argument and accumulate these names
30 rc_names = [
31 mark.args[0]
32 for mark in item.iter_markers(name="skip_if_rc_var_not_set")
33 ]
34
35 # checks all names mentioned are set in ~/.bobrc, otherwise, skip the test
36 if rc_names:
37 missing = [k for k in rc_names if (k not in bob.extension.rc)]
38 if any(missing):
39 pytest.skip(f"Test skipped because {', '.join(missing)} are **not** "
40 f"set in ~/.bobrc")
41
42
43def rc_variable_set(name):
44 pytest.mark.skipif(
45 name not in bob.extension.rc,
46 reason=f"Bob's RC variable '{name}' is not set",
47 )