Closed jdebacker closed 3 months ago
Follow up. I've been able to run pytest tests/test_module_name.py
for most modules. The only one I've noted giving an error like the above is test_parameter_plots.py
. So perhaps issues with with M1, 3.12, and a package called there?
Following up on this issue... it appears the issue is with reading files that were saved via CloudPickle in versions of Python < 3.12.
I have no problems running the model generally, but when running tests, those test modules that import objects saved via CloudPickle (e.g., Specifications
objects or tax functions of the mono
form) such as test_parameter_plots.py
and test_ouptut_tables.py
, I get a failure:
(ogcore-dev) jason.debacker@JDEBACKER-8 OG-Core % pytest tests/test_parameter_plots.py
============================= test session starts ==============================
platform darwin -- Python 3.12.3, pytest-8.2.2, pluggy-1.5.0
rootdir: /Users/jason.debacker/repos/OG-Core
configfile: pytest.ini
plugins: cov-5.0.0, anyio-4.4.0, xdist-3.6.1
collecting ... zsh: trace trap pytest tests/test_parameter_plots.py
The lack of any traceback makes it not clear, but I if I comment out the lines reading in these CloudPickled files, I do get some tests collected and run (of course there is an error noting that I don't the the parameters object available since I didn't import it, but we can at least see that tests try to run):
(ogcore-dev) jason.debacker@JDEBACKER-8 OG-Core % pytest tests/test_parameter_plots.py
============================= test session starts ==============================
platform darwin -- Python 3.12.3, pytest-8.2.2, pluggy-1.5.0
rootdir: /Users/jason.debacker/repos/OG-Core
configfile: pytest.ini
plugins: cov-5.0.0, anyio-4.4.0, xdist-3.6.1
collected 1 item
tests/test_parameter_plots.py F [100%]
=================================== FAILURES ===================================
_____________________________ test_plot_imm_rates ______________________________
def test_plot_imm_rates():
fig = parameter_plots.plot_imm_rates(
> base_params.imm_rates,
base_params.start_year,
[base_params.start_year],
include_title=True,
)
E NameError: name 'base_params' is not defined
tests/test_parameter_plots.py:46: NameError
=========================== short test summary info ============================
FAILED tests/test_parameter_plots.py::test_plot_imm_rates - NameError: name 'base_params' is not defined
============================== 1 failed in 1.83s ===============================
We already have separate parameter files for Python 3.11 and Python 3.9/10:
if sys.version_info[1] < 11:
base_params = utils.safe_read_pickle(
os.path.join(CUR_PATH, "test_io_data", "model_params_baseline.pkl")
)
else:
base_params = utils.safe_read_pickle(
os.path.join(
CUR_PATH, "test_io_data", "model_params_baseline_v311.pkl"
)
)
Other times, we don't run certain parameterizations under a different Python version:
if sys.version_info[1] < 11:
test_list = [
(base_taxfunctions, 43, "DEP", "etr", True, None, None),
(base_taxfunctions, 43, "DEP", "etr", False, None, "Test title"),
(GS_nonage_spec_taxfunctions, None, "GS", "etr", True, None, None),
(base_taxfunctions, 43, "DEP", "etr", True, [micro_data], None),
(base_taxfunctions, 43, "DEP", "mtry", True, [micro_data], None),
(base_taxfunctions, 43, "DEP", "mtrx", True, [micro_data], None),
(mono_nonage_spec_taxfunctions, None, "mono", "etr", True, None, None),
]
id_list = [
"over_labinc=True",
"over_labinc=False",
"Non age-specific",
"with data",
"MTR capital income",
"MTR labor income",
"Mono functions",
]
else:
test_list = [
(base_taxfunctions, 43, "DEP", "etr", True, None, None),
(base_taxfunctions, 43, "DEP", "etr", False, None, "Test title"),
(GS_nonage_spec_taxfunctions, None, "GS", "etr", True, None, None),
(base_taxfunctions, 43, "DEP", "etr", True, [micro_data], None),
(base_taxfunctions, 43, "DEP", "mtry", True, [micro_data], None),
(base_taxfunctions, 43, "DEP", "mtrx", True, [micro_data], None),
]
id_list = [
"over_labinc=True",
"over_labinc=False",
"Non age-specific",
"with data",
"MTR capital income",
"MTR labor income",
]
@pytest.mark.parametrize(
"tax_funcs,age,tax_func_type,rate_type,over_labinc,data,title",
test_list,
ids=id_list,
)
def test_plot_2D_taxfunc(
tax_funcs, age, tax_func_type, rate_type, over_labinc, data, title
):
"""
Test of plot_2D_taxfunc
"""
if sys.version_info[1] < 11:
fig = parameter_plots.plot_2D_taxfunc(
2030,
2021,
[tax_funcs],
age=age,
tax_func_type=[tax_func_type],
rate_type=rate_type,
over_labinc=over_labinc,
data_list=data,
title=title,
)
assert fig
else:
assert True
@rickecon What do you want to do for Python 3.12? Create a third pkl
file for parameters? Skip tests that require these Cloudpickled objects on 3.12? Note we may have to update this with each Python version we want to test against because CloudPickle is not really suited for long term storage due to changes in Python.
Resolved with PR #969
I recently rebuilt the
ogcore-dev
environment and tried to run the OG-Core testing suite. It resulted in an error when collecting tests:I've not seen this before an a quick search didn't reveal an obvious solution.