|
| 1 | +import pytest |
| 2 | + |
| 3 | + |
| 4 | +configure_is_imported = False |
| 5 | + |
| 6 | + |
| 7 | +def pytest_configure(config): |
| 8 | + global configure_is_imported |
| 9 | + if not configure_is_imported: |
| 10 | + configure_is_imported = True |
| 11 | + # filter expected warnings |
| 12 | + config.addinivalue_line( |
| 13 | + "filterwarnings", |
| 14 | + "ignore:No geometry type found, no coordinates will be added:UserWarning", |
| 15 | + ) |
| 16 | + config.addinivalue_line( |
| 17 | + "filterwarnings", |
| 18 | + "ignore:deallocating CachingFileManager.*, but file is not already closed. " |
| 19 | + "This may indicate a bug.:RuntimeWarning", |
| 20 | + ) |
| 21 | + |
| 22 | + # register additional markers |
| 23 | + config.addinivalue_line( |
| 24 | + "markers", |
| 25 | + "long: long test, or one of many permutations (disabled by default)", |
| 26 | + ) |
| 27 | + config.addinivalue_line( |
| 28 | + "markers", |
| 29 | + "flaky: xarray uses this mark, adding to avoid warnings about it not being " |
| 30 | + "defined", |
| 31 | + ) |
| 32 | + config.addinivalue_line( |
| 33 | + "markers", |
| 34 | + "network: xarray uses this mark, adding to avoid warnings about it not " |
| 35 | + "being defined", |
| 36 | + ) |
| 37 | + config.addinivalue_line( |
| 38 | + "markers", |
| 39 | + "slow: xarray uses this mark, adding to avoid warnings about it not being " |
| 40 | + "defined", |
| 41 | + ) |
| 42 | + |
| 43 | + |
| 44 | +addoption_is_imported = False |
| 45 | + |
| 46 | + |
| 47 | +def pytest_addoption(parser): |
| 48 | + # Add command line option '--long' for pytest, to be used to enable long tests |
| 49 | + global addoption_is_imported |
| 50 | + if not addoption_is_imported: |
| 51 | + addoption_is_imported = True |
| 52 | + parser.addoption( |
| 53 | + "--long", |
| 54 | + action="store_true", |
| 55 | + default=False, |
| 56 | + help="enable tests marked as 'long'", |
| 57 | + ) |
| 58 | + |
| 59 | + |
| 60 | +collection_is_imported = False |
| 61 | + |
| 62 | + |
| 63 | +def pytest_collection_modifyitems(config, items): |
| 64 | + global collection_is_imported |
| 65 | + if not collection_is_imported: |
| 66 | + collection_is_imported = True |
| 67 | + if not config.getoption("--long"): |
| 68 | + # --long not given in cli: skip long tests |
| 69 | + print("\n skipping long tests, pass '--long' to enable") |
| 70 | + skip_long = pytest.mark.skip(reason="need --long option to run") |
| 71 | + for item in items: |
| 72 | + if "long" in item.keywords: |
| 73 | + item.add_marker(skip_long) |
0 commit comments