Skip to content

Commit

Permalink
pass hooks pytest_config.py via pytest config file (#287)
Browse files Browse the repository at this point in the history
Unify how pytest config is loaded in all the model packages and make it available also when running tests from the repository base directory: pass `pytest_config.py` through `addopts` in the `pytest` inif files.
  • Loading branch information
halungge authored Oct 9, 2023
1 parent 6ff0dc0 commit 83d82cb
Show file tree
Hide file tree
Showing 12 changed files with 11 additions and 42 deletions.
22 changes: 3 additions & 19 deletions model/atmosphere/advection/advection_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,8 @@
# distribution for a copy of the license or check <https://www.gnu.org/licenses/>.
#
# SPDX-License-Identifier: GPL-3.0-or-later
import pytest
from gt4py.next.program_processors.runners.roundtrip import executor

from icon4py.model.common.test_utils.simple_mesh import SimpleMesh


BACKENDS = {"embedded": executor}
MESHES = {"simple_mesh": SimpleMesh()}


@pytest.fixture(
ids=MESHES.keys(),
params=MESHES.values(),
from icon4py.model.common.test_utils.fixtures import ( # noqa : F401 # fixtures from test_utils
backend,
mesh,
)
def mesh(request):
return request.param


@pytest.fixture(ids=BACKENDS.keys(), params=BACKENDS.values())
def backend(request):
return request.param
1 change: 1 addition & 0 deletions model/atmosphere/advection/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ warn_unused_ignores = true
[tool.pytest]

[tool.pytest.ini_options]
addopts = ['-p icon4py.model.common.test_utils.pytest_config']
markers = 'slow_tests: marks tests as slow'
testpaths = ['tests', 'advection_tests']

Expand Down
6 changes: 0 additions & 6 deletions model/atmosphere/diffusion/diffusion_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,6 @@
step_date_exit,
step_date_init,
)
from icon4py.model.common.test_utils.pytest_config import ( # noqa: F401
pytest_addoption,
pytest_configure,
pytest_generate_tests,
pytest_runtest_setup,
)


@pytest.fixture
Expand Down
1 change: 1 addition & 0 deletions model/atmosphere/diffusion/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ warn_unused_ignores = true
[tool.pytest]

[tool.pytest.ini_options]
addopts = ['-p icon4py.model.common.test_utils.pytest_config']
markers = [
"datatest: test depending on serialized data generated by a full model run"
]
Expand Down
1 change: 1 addition & 0 deletions model/atmosphere/dycore/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ warn_unused_ignores = true
[tool.pytest]

[tool.pytest.ini_options]
addopts = ['-p icon4py.model.common.test_utils.pytest_config']
testpaths = 'tests'

[tool.setuptools.dynamic]
Expand Down
6 changes: 0 additions & 6 deletions model/atmosphere/dycore/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,3 @@
step_date_exit,
step_date_init,
)
from icon4py.model.common.test_utils.pytest_config import ( # noqa: F401
pytest_addoption,
pytest_configure,
pytest_generate_tests,
pytest_runtest_setup,
)
1 change: 1 addition & 0 deletions model/common/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ warn_unused_ignores = true
[tool.pytest]

[tool.pytest.ini_options]
addopts = ['-p icon4py.model.common.test_utils.pytest_config']
markers = [
"datatest: test depending on serialized data generated by a full model run",
"with_netcdf: test depending on a compatible version of netCDF4"
Expand Down
6 changes: 0 additions & 6 deletions model/common/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,6 @@
processor_props,
ranked_data_path,
)
from icon4py.model.common.test_utils.pytest_config import ( # noqa: F401
pytest_addoption,
pytest_configure,
pytest_generate_tests,
pytest_runtest_setup,
)


grids_path = base_path.joinpath("grids")
Expand Down
1 change: 1 addition & 0 deletions model/driver/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ warn_unused_ignores = true
[tool.pytest]

[tool.pytest.ini_options]
addopts = ['-p icon4py.model.common.test_utils.pytest_config']
testpaths = 'tests'

[tool.setuptools.dynamic]
Expand Down
5 changes: 0 additions & 5 deletions model/driver/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,3 @@
processor_props,
ranked_data_path,
)
from icon4py.model.common.test_utils.pytest_config import ( # noqa: F401
pytest_addoption,
pytest_configure,
pytest_runtest_setup,
)
2 changes: 2 additions & 0 deletions model/tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,5 @@ skip_install = true
commands =
commands_post =

[pytest]
addopts = -p icon4py.model.common.test_utils.pytest_config
1 change: 1 addition & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ markers =
slow_tests: mark test as slow.
datatest: test depending on serialized data generated by a full model run
with_netcdf: test depending on a compatible version of netCDF4
addopts = -p icon4py.model.common.test_utils.pytest_config

0 comments on commit 83d82cb

Please sign in to comment.