Coverage for /scratch/builds/bob/bob.med.tb/miniconda/conda-bld/bob.med.tb_1637571489937/_test_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placeho/lib/python3.8/site-packages/bob/med/tb/test/conftest.py: 92%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

13 statements  

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 )