1#!/usr/bin/env python
2# coding=utf-8
3
4import pytest
5
6import bob.extension
7
8
9def pytest_configure(config):
10 """This function is run once for pytest setup"""
11
12 config.addinivalue_line(
13 "markers",
14 "skip_if_rc_var_not_set(name): this mark skips the test if a certain "
15 "~/.bobrc variable is not set",
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(
40 f"Test skipped because {', '.join(missing)} are **not** "
41 f"set in ~/.bobrc"
42 )
43
44
45def rc_variable_set(name):
46 pytest.mark.skipif(
47 name not in bob.extension.rc,
48 reason=f"Bob's RC variable '{name}' is not set",
49 )