Skip to content

Commit

Permalink
Further cleanup of testing suite (#971)
Browse files Browse the repository at this point in the history
Co-authored-by: deepsource-autofix[bot] <62050782+deepsource-autofix[bot]@users.noreply.github.com>
  • Loading branch information
Andrew-S-Rosen and deepsource-autofix[bot] authored Sep 25, 2023
1 parent cfd7916 commit 8db8d30
Show file tree
Hide file tree
Showing 82 changed files with 335 additions and 454 deletions.
22 changes: 11 additions & 11 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,15 @@ jobs:
- name: Make quacc config
run: quacc set WORKFLOW_ENGINE covalent

- name: Start Covalent server
run: covalent start

- name: Run tests with pytest
run: pytest -k 'covalent' --cov=quacc --cov-report=xml

- name: Stop Covalent server
run: covalent stop

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
if: github.repository == 'Quantum-Accelerators/quacc'
Expand Down Expand Up @@ -121,7 +127,7 @@ jobs:
run: quacc set WORKFLOW_ENGINE ${{ matrix.wflow_engine }}

- name: Run tests with pytest
run: pytest tests/${{ matrix.wflow_engine }}_tests --cov=quacc --cov-report=xml
run: pytest -k '${{ matrix.wflow_engine }}' --cov=quacc --cov-report=xml

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
Expand Down Expand Up @@ -201,15 +207,12 @@ jobs:
activate-environment: quacc-env

- name: Install conda packages
run: |
conda install -n base conda-libmamba-solver
conda install -c conda-forge dftbplus
run: conda install -c conda-forge dftbplus

- name: Install pip packages
run: |
pip install -r tests/requirements.txt
pip install -r tests/requirements-tblite.txt
pip install -r tests/requirements-defects.txt
pip install -r tests/requirements-tblite-dftbplus-defects.txt
pip install .[dev]
- name: Run tests with pytest
Expand Down Expand Up @@ -248,15 +251,12 @@ jobs:
activate-environment: quacc-env

- name: Install conda packages
run: |
conda install -n base conda-libmamba-solver
conda install -c conda-forge openbabel
run: conda install -c conda-forge openbabel

- name: Install pip packages
run: |
pip install -r tests/requirements.txt
pip install -r tests/requirements-optimizers.txt
pip install -r tests/requirements-newtonnet.txt
pip install -r tests/requirements-qchem-sella-newtonnet.txt
pip install .[dev]
- name: Run tests with pytest
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ exclude = ["**/__pycache__"]

[tool.pytest.ini_options]
minversion = "6.0"
addopts = ["-p no:warnings"]
addopts = ["-p no:warnings", "--import-mode=importlib"]
xfail_strict = true
log_cli_level = "warn"
testpaths = ["tests"]
Expand All @@ -101,6 +101,7 @@ source = ["src"]
exclude_lines = [
"if TYPE_CHECKING:",
"if __name__ == .__main__.:",
"except ImportError:",
]

[tool.ruff]
Expand Down
4 changes: 2 additions & 2 deletions src/quacc/utils/wflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ def job(_func: Callable | None = None, **kwargs) -> Job:
All `#!Python @job`-decorated functions are transformed into their corresponding
decorator.
The wrapped function can also be stripped of its decorator
by calling the `#!Python .__wrapped__` attribute.
The wrapped function can also be stripped of its decorator by calling the
`#!Python .__wrapped__` attribute.
```python
from quacc import job
Expand Down
10 changes: 0 additions & 10 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import contextlib
import os
import subprocess
from pathlib import Path
from shutil import rmtree

Expand All @@ -17,14 +15,6 @@ def pytest_sessionstart():
os.makedirs(SETTINGS.RESULTS_DIR, exist_ok=True)
os.makedirs(SETTINGS.SCRATCH_DIR, exist_ok=True)

if SETTINGS.WORKFLOW_ENGINE == "covalent":
subprocess.run(["covalent", "start"], check=True)
elif SETTINGS.WORKFLOW_ENGINE == "parsl":
import parsl

with contextlib.suppress(Exception):
parsl.load()


def pytest_sessionfinish():
rmtree(TEST_RESULTS_DIR, ignore_errors=True)
Expand Down
19 changes: 5 additions & 14 deletions tests/covalent_tests/test_covalent_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,15 @@
import pytest
from maggma.stores import MemoryStore

try:
import covalent as ct
ct = pytest.importorskip("covalent")

except ImportError:
ct = None


@pytest.mark.skipif(
ct is None or os.environ.get("GITHUB_ACTIONS", False) is False,
pytestmark = pytest.mark.skipif(
os.environ.get("GITHUB_ACTIONS", False) is False,
reason="This test is only meant to be run on GitHub Actions with Covalent",
)
def test_covalent_to_db():
import covalent as ct


def test_covalent_to_db():
from quacc.utils.db import covalent_to_db

@ct.electron
Expand Down Expand Up @@ -52,10 +47,6 @@ def workflow(a, b):
covalent_to_db(store, dispatch_ids=["bad-value"], results_dir="bad-value")


@pytest.mark.skipif(
ct is None or os.environ.get("GITHUB_ACTIONS", False) is False,
reason="This test is only meant to be run on GitHub Actions with Covalent",
)
def test_covalent_db_tutorial():
# Connect to the database

Expand Down
14 changes: 6 additions & 8 deletions tests/covalent_tests/test_covalent_syntax.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import pytest

from quacc import flow, job, subflow
from quacc import SETTINGS, flow, job, subflow

try:
import covalent as ct
ct = pytest.importorskip("covalent")
pytestmark = pytest.mark.skipif(
SETTINGS.WORKFLOW_ENGINE != "covalent",
reason="Requires Covalent as the workflow manager",
)

except ImportError:
ct = None


@pytest.mark.skipif(ct is None, reason="This test requires Covalent")
def test_covalent_decorators(tmpdir):
tmpdir.chdir()

Expand Down Expand Up @@ -56,7 +55,6 @@ def dynamic_workflow(a, b, c):
]


@pytest.mark.skipif(ct is None, reason="This test requires Covalent")
def test_covalent_decorators_args(tmpdir):
tmpdir.chdir()

Expand Down
24 changes: 7 additions & 17 deletions tests/covalent_tests/test_covalent_tutorials.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import pytest
from ase.build import bulk

from quacc import flow
from quacc import SETTINGS, flow
from quacc.recipes.emt.core import relax_job, static_job

try:
import covalent as ct
ct = pytest.importorskip("covalent")


except ImportError:
ct = None
pyttestmark = pytest.mark.skipif(
SETTINGS.WORKFLOW_ENGINE != "covalent",
reason="This test requires Covalent as the workflow engine",
)


@pytest.mark.skipif(ct is None, reason="This test requires Covalent")
def test_quickstart(tmpdir):
tmpdir.chdir()

Expand All @@ -31,7 +32,6 @@ def test_quickstart(tmpdir):
assert result.status == "COMPLETED"


@pytest.mark.skipif(ct is None, reason="This test requires Covalent")
def test_tutorial1a(tmpdir):
tmpdir.chdir()

Expand All @@ -56,7 +56,6 @@ def test_tutorial1a(tmpdir):
assert result.status == "COMPLETED"


@pytest.mark.skipif(ct is None, reason="This test requires Covalent")
def test_tutorial1b(tmpdir):
tmpdir.chdir()

Expand All @@ -71,7 +70,6 @@ def test_tutorial1b(tmpdir):
assert result.status == "COMPLETED"


@pytest.mark.skipif(ct is None, reason="This test requires Covalent")
def test_tutorial2a(tmpdir):
tmpdir.chdir()
import covalent as ct
Expand Down Expand Up @@ -101,7 +99,6 @@ def workflow(atoms):
assert result.status == "COMPLETED"


@pytest.mark.skipif(ct is None, reason="This test requires Covalent")
def test_tutorial2b(tmpdir):
tmpdir.chdir()

Expand Down Expand Up @@ -131,7 +128,6 @@ def workflow(atoms1, atoms2):
assert result.status == "COMPLETED"


@pytest.mark.skipif(ct is None, reason="This test requires Covalent")
def test_tutorial2c(tmpdir):
tmpdir.chdir()

Expand All @@ -153,7 +149,6 @@ def workflow(atoms):
assert result.status == "COMPLETED"


@pytest.mark.skipif(ct is None, reason="This test requires Covalent")
def test_tutorial_excecutor1(tmpdir):
tmpdir.chdir()

Expand All @@ -168,7 +163,6 @@ def workflow4(atoms):
assert result.status == "COMPLETED"


@pytest.mark.skipif(ct is None, reason="This test requires Covalent")
def test_tutorial_excecutor2(tmpdir):
tmpdir.chdir()

Expand All @@ -186,7 +180,6 @@ def workflow5(atoms):
assert result.status == "COMPLETED"


@pytest.mark.skipif(ct is None, reason="This test requires Covalent")
def test_comparison1(tmpdir):
tmpdir.chdir()

Expand Down Expand Up @@ -215,7 +208,6 @@ def workflow(a, b, c):
assert result.status == "COMPLETED"


@pytest.mark.skipif(ct is None, reason="This test requires Covalent")
def test_comparison2(tmpdir):
tmpdir.chdir()

Expand Down Expand Up @@ -251,7 +243,6 @@ def workflow(a, b, c):
assert result.status == "COMPLETED"


@pytest.mark.skipif(ct is None, reason="This test requires Covalent")
def test_comparison3(tmpdir):
tmpdir.chdir()
import covalent as ct
Expand All @@ -275,7 +266,6 @@ def workflow(a, b, c):
assert result.status == "COMPLETED"


@pytest.mark.skipif(ct is None, reason="This test requires Covalent")
def test_comparison4(tmpdir):
tmpdir.chdir()

Expand Down
9 changes: 1 addition & 8 deletions tests/custodian_tests/test_qchem_custodian.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import pytest
from custodian import Custodian

try:
import openbabel as ob
except ImportError:
ob = None
ob = pytest.importorskip("openbabel")


class MockRun:
Expand Down Expand Up @@ -33,10 +30,6 @@ def patch_custodian_run(monkeypatch):
monkeypatch.setattr(Custodian, "run", mock_custodian_run)


@pytest.mark.skipif(
ob is None,
reason="Openbabel needed for test.",
)
def test_run_qchem_custodian(monkeypatch):
from quacc.custodian.qchem import run_custodian

Expand Down
16 changes: 7 additions & 9 deletions tests/jobflow_tests/test_jobflow_syntax.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
import pytest
from maggma.stores import MemoryStore

from quacc import flow, job, subflow
from quacc import SETTINGS, flow, job, subflow

try:
import jobflow as jf
jf = pytest.importorskip("jobflow")

except ImportError:
jf = None
pytestmark = pytest.mark.skipif(
SETTINGS.WORKFLOW_ENGINE != "jobflow",
reason="Jobflow needs to be the workflow engine",
)

if jf:
STORE = jf.JobStore(MemoryStore())
STORE = jf.JobStore(MemoryStore())


@pytest.mark.skipif(jf is None, reason="Jobflow not installed")
def test_jobflow_decorators(tmpdir):
tmpdir.chdir()

Expand Down Expand Up @@ -41,7 +40,6 @@ def workflow(a, b, c):
assert isinstance(add_distributed([1, 2, 3], 4)[0], jf.Job)


@pytest.mark.skipif(jf is None, reason="Jobflow not installed")
def test_jobflow_decorators_args(tmpdir):
tmpdir.chdir()

Expand Down
Loading

0 comments on commit 8db8d30

Please sign in to comment.