From ae05829a660488590d7d268c97c97f59d55f6c75 Mon Sep 17 00:00:00 2001 From: peterdudfield Date: Tue, 5 Nov 2024 11:31:56 +0000 Subject: [PATCH 1/4] only make data fixtures once --- tests/conftest.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 0194e15..a06a961 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -115,7 +115,7 @@ def make_nwp_data(shell_path, varname, test_t0): return ds -@pytest.fixture +@pytest.fixture(scope="session") def nwp_ukv_data(test_t0): return make_nwp_data( shell_path=f"{os.path.dirname(os.path.abspath(__file__))}/test_data/nwp_ukv_shell.zarr", @@ -124,7 +124,7 @@ def nwp_ukv_data(test_t0): ) -@pytest.fixture +@pytest.fixture(scope="session") def nwp_ecmwf_data(test_t0): return make_nwp_data( shell_path=f"{os.path.dirname(os.path.abspath(__file__))}/test_data/nwp_ecmwf_shell.zarr", @@ -168,25 +168,25 @@ def make_sat_data(test_t0, delay_mins, freq_mins): return ds -@pytest.fixture() +@pytest.fixture(scope="session") def sat_5_data(test_t0): return make_sat_data(test_t0, delay_mins=10, freq_mins=5) -@pytest.fixture() +@pytest.fixture(scope="session") def sat_5_data_zero_delay(test_t0): return make_sat_data(test_t0, delay_mins=0, freq_mins=5) -@pytest.fixture() +@pytest.fixture(scope="session") def sat_5_data_delayed(test_t0): return make_sat_data(test_t0, delay_mins=120, freq_mins=5) -@pytest.fixture() +@pytest.fixture(scope="session") def sat_15_data(test_t0): return make_sat_data(test_t0, delay_mins=0, freq_mins=15) -@pytest.fixture() +@pytest.fixture(scope="session") def gsp_yields_and_systems(db_session, test_t0): """Create gsp yields and systems""" @@ -225,7 +225,7 @@ def gsp_yields_and_systems(db_session, test_t0): } -@pytest.fixture() +@pytest.fixture(scope="session") def me_latest(db_session): metric_values = make_fake_me_latest(session=db_session, model_name="pvnet_v2") db_session.add_all(metric_values) From 5527de917eb2e7cc4d5ad4186331c010d25fe35f Mon Sep 17 00:00:00 2001 From: peterdudfield Date: Tue, 5 Nov 2024 11:39:41 +0000 Subject: [PATCH 2/4] fix --- tests/conftest.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index a06a961..d0caccd 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -20,7 +20,7 @@ xr.set_options(keep_attrs=True) -@pytest.fixture() +@pytest.fixture(scope="session") def test_t0(): return pd.Timestamp.now(tz=None).floor(timedelta(minutes=30)) @@ -186,7 +186,7 @@ def sat_15_data(test_t0): return make_sat_data(test_t0, delay_mins=0, freq_mins=15) -@pytest.fixture(scope="session") +@pytest.fixture() def gsp_yields_and_systems(db_session, test_t0): """Create gsp yields and systems""" @@ -225,7 +225,7 @@ def gsp_yields_and_systems(db_session, test_t0): } -@pytest.fixture(scope="session") +@pytest.fixture() def me_latest(db_session): metric_values = make_fake_me_latest(session=db_session, model_name="pvnet_v2") db_session.add_all(metric_values) From 474e726a36265c2f02b3d7ad70cdcc9b9bf43089 Mon Sep 17 00:00:00 2001 From: peterdudfield Date: Tue, 5 Nov 2024 11:54:21 +0000 Subject: [PATCH 3/4] change to fixture to module --- tests/conftest.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index d0caccd..8bca352 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -20,7 +20,7 @@ xr.set_options(keep_attrs=True) -@pytest.fixture(scope="session") +@pytest.fixture(scope="module") def test_t0(): return pd.Timestamp.now(tz=None).floor(timedelta(minutes=30)) @@ -115,7 +115,7 @@ def make_nwp_data(shell_path, varname, test_t0): return ds -@pytest.fixture(scope="session") +@pytest.fixture(scope="module") def nwp_ukv_data(test_t0): return make_nwp_data( shell_path=f"{os.path.dirname(os.path.abspath(__file__))}/test_data/nwp_ukv_shell.zarr", @@ -124,7 +124,7 @@ def nwp_ukv_data(test_t0): ) -@pytest.fixture(scope="session") +@pytest.fixture(scope="module") def nwp_ecmwf_data(test_t0): return make_nwp_data( shell_path=f"{os.path.dirname(os.path.abspath(__file__))}/test_data/nwp_ecmwf_shell.zarr", @@ -168,20 +168,20 @@ def make_sat_data(test_t0, delay_mins, freq_mins): return ds -@pytest.fixture(scope="session") +@pytest.fixture(scope="module") def sat_5_data(test_t0): return make_sat_data(test_t0, delay_mins=10, freq_mins=5) -@pytest.fixture(scope="session") +@pytest.fixture(scope="module") def sat_5_data_zero_delay(test_t0): return make_sat_data(test_t0, delay_mins=0, freq_mins=5) -@pytest.fixture(scope="session") +@pytest.fixture(scope="module") def sat_5_data_delayed(test_t0): return make_sat_data(test_t0, delay_mins=120, freq_mins=5) -@pytest.fixture(scope="session") +@pytest.fixture(scope="module") def sat_15_data(test_t0): return make_sat_data(test_t0, delay_mins=0, freq_mins=15) From 25557110cc7b5c7e6e8c74ed59e3c0d06d747ffb Mon Sep 17 00:00:00 2001 From: peterdudfield Date: Tue, 5 Nov 2024 12:09:30 +0000 Subject: [PATCH 4/4] update warning --- pvnet_app/app.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pvnet_app/app.py b/pvnet_app/app.py index 5bc6b53..6250eb6 100644 --- a/pvnet_app/app.py +++ b/pvnet_app/app.py @@ -218,7 +218,8 @@ def app( # Store the config filename so we can create batches suitable for all models data_config_paths.append(data_config_path) else: - warnings.warn(f"The model {model_config.name} cannot be run with input data available") + message = f"The model {model_config.name} cannot be run with input data available" + warnings.warn(message) if len(forecast_compilers) == 0: raise Exception(f"No models were compatible with the available input data.")