From 2ec1d29dde8ad7854936a8b45c767d140386dfa3 Mon Sep 17 00:00:00 2001 From: "Matthew W. Thompson" Date: Tue, 13 Feb 2024 08:15:14 -0600 Subject: [PATCH] Update configuration --- .github/workflows/CI.yml | 2 +- .github/workflows/beta_rc.yaml | 2 +- .github/workflows/conda.yml | 9 ++- openff/toolkit/_tests/conftest.py | 94 ------------------------ openff/toolkit/_tests/test_forcefield.py | 2 +- pytest.ini | 4 + 6 files changed, 13 insertions(+), 100 deletions(-) create mode 100644 pytest.ini diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index fff552d58..736eb5fb8 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -142,7 +142,7 @@ jobs: PYTEST_ARGS+=" --ignore=openff/toolkit/_tests/test_examples.py" PYTEST_ARGS+=" --ignore=openff/toolkit/_tests/test_links.py" if [[ "$GITHUB_EVENT_NAME" == "schedule" ]]; then - PYTEST_ARGS+=" --runslow" + PYTEST_ARGS+=" -m 'slow or not slow'" fi python -m pytest $PYTEST_ARGS $COV diff --git a/.github/workflows/beta_rc.yaml b/.github/workflows/beta_rc.yaml index 45dab90de..f01f3e3fb 100644 --- a/.github/workflows/beta_rc.yaml +++ b/.github/workflows/beta_rc.yaml @@ -77,7 +77,7 @@ jobs: run: | PYTEST_ARGS+=" --ignore=openff/toolkit/_tests/test_examples.py" PYTEST_ARGS+=" --ignore=openff/toolkit/_tests/test_links.py" - PYTEST_ARGS+=" --runslow" + PYTEST_ARGS+=" -m 'slow or not slow'" pytest $PYTEST_ARGS $COV - name: Run code snippets in docs diff --git a/.github/workflows/conda.yml b/.github/workflows/conda.yml index a21e7969a..1e0aa565a 100644 --- a/.github/workflows/conda.yml +++ b/.github/workflows/conda.yml @@ -28,7 +28,7 @@ jobs: env: OPENEYE: ${{ matrix.openeye }} OE_LICENSE: ${{ github.workspace }}/oe_license.txt - PYTEST_ARGS: -r fE --tb=short -n logical + PYTEST_ARGS: -r fE --tb=short -n logical --durations=20 steps: - name: Vanilla install from conda @@ -87,12 +87,15 @@ jobs: - name: Test the package run: | + + # Act like we're testing with this patch deployed ... + python -m pip install -e . utilities/test_plugins/ + if [[ "$OPENEYE" == true ]]; then python -c "import openff.toolkit; print(openff.toolkit.__file__)" python -c "import openeye; print(openeye.oechem.OEChemIsLicensed())" fi - PYTEST_ARGS+=" -x --trace-config" PYTEST_ARGS+=" --ignore-glob='*_links.py'" PYTEST_ARGS+=" --ignore-glob='*_examples.py'" PYTEST_ARGS+=" --ignore-glob='*_nagl.py'" @@ -101,4 +104,4 @@ jobs: python -m pytest $PYTEST_ARGS \ --pyargs "openff.toolkit" \ - $CONDA_PREFIX/lib/python3.11/site-packages/openff/toolkit/_tests/conftest.py + -m "slow or not slow" diff --git a/openff/toolkit/_tests/conftest.py b/openff/toolkit/_tests/conftest.py index 7fd3d0796..9233d7965 100644 --- a/openff/toolkit/_tests/conftest.py +++ b/openff/toolkit/_tests/conftest.py @@ -1,15 +1,9 @@ """ Configuration file for pytest. - -This adds the following command line options. -- runslow: Run tests marked as slow (default is False). - """ import logging -import pytest - logger = logging.getLogger(__name__) # Ensure QCPortal is imported before any OpenEye modules, see @@ -20,16 +14,6 @@ pass -def pytest_configure(config): - """ - Initialization hook to register custom markers without a pytest.ini - More info: https://docs.pytest.org/en/latest/reference.html#initialization-hooks - """ - config.addinivalue_line( - "markers", "slow: marks tests as slow (deselect with `-m 'not slow'`)" - ) - - def untar_full_alkethoh_and_freesolv_set(): """When running slow tests, we unpack the full AlkEthOH and FreeSolv test sets in advance to speed things up. @@ -48,81 +32,3 @@ def untar_full_alkethoh_and_freesolv_set(): tarfile_path = os.path.join(molecule_dir_path, tarfile_name) with tarfile.open(tarfile_path, "r:gz") as tar: tar.extractall(path=molecule_dir_path) - - -def pytest_addoption(parser): - """Add the pytest command line option --runslow and --failwip. - - If --runslow is not given, tests marked with pytest.mark.slow are - skipped. - - If --failwip is not given, tests marked with pytest.mark.wip are - xfailed. - - Parameters - ---------- - parser : argparsing.parser - The parser used by pytest to process arguments - - Returns - ------- - None - - """ - - # Loaded pytest plugins define their own arguments, and in certain cases - # our options use the same name. Although this can define two different - # behaviors for the same argument, the two options below are fairly - # unambiguous in their interpretation, so we skip any errors and allow - # the testing to proceed - - try: - parser.addoption( - "--runslow", action="store_true", default=False, help="run slow tests" - ) - except ValueError: - logger.warning( - "Option --runslow already added elsewhere (from a plugin possibly?). Skipping..." - ) - - try: - parser.addoption( - "--failwip", - action="store_true", - default=False, - help="fail work in progress tests", - ) - except ValueError: - logger.warning( - "Option --failwip already added elsewhere (from a plugin possibly?). Skipping..." - ) - - -def pytest_collection_modifyitems(config, items): - if config.getoption("runslow"): - # If --runslow is given, we don't have to mark items for skipping, - # but we need to extract the whole AlkEthOH and FreeSolv sets (see - # test_forcefield::test_alkethoh/freesolv_parameters_assignment). - untar_full_alkethoh_and_freesolv_set() - else: - # Mark for skipping all items marked as slow. - skip_slow = pytest.mark.skip( - reason="specify --runslow pytest option to run this test." - ) - for item in items: - if "slow" in item.keywords: - item.add_marker(skip_slow) - - # Mark work-in-progress tests for xfail. - if not config.getoption("failwip"): - xfail_wip_reason = ( - "This is a work in progress test. Specify " - "--failwip pytest option to make this test fail." - ) - for item in items: - if "wip" in item.keywords: - # Augment original reason. - reason = xfail_wip_reason + item.get_closest_marker("wip").kwargs.get( - "reason", "" - ) - item.add_marker(pytest.mark.xfail(reason=reason)) diff --git a/openff/toolkit/_tests/test_forcefield.py b/openff/toolkit/_tests/test_forcefield.py index bbbd4ad3b..1ab4582f0 100644 --- a/openff/toolkit/_tests/test_forcefield.py +++ b/openff/toolkit/_tests/test_forcefield.py @@ -1347,7 +1347,7 @@ def test_parameterize_large_system( force_field, ): """Test parameterizing a large system of several distinct molecules. - This test is very slow, so it is only run if the --runslow option is provided to pytest. + This test is very slow, so it is only run if the slow marker option is provided to pytest. """ box_file_path = get_data_file_path( os.path.join("systems", "packmol_boxes", box) diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 000000000..a997e0e7f --- /dev/null +++ b/pytest.ini @@ -0,0 +1,4 @@ +[pytest] +markers = + slow: marks tests as slow (deselect with '-m "not slow"') +addopts = -m "not slow"