Skip to content

Commit b9da890

Browse files
authored
Update tests to work with Pytest v8 (#1275)
1 parent 92e5b13 commit b9da890

File tree

4 files changed

+22
-27
lines changed

4 files changed

+22
-27
lines changed

tests/test_consumables.py

+17-18
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def test_unrecognised_item_code_is_recorded(seed):
9696
assert cons._not_recognised_item_codes # Some item_codes recorded as not recognised.
9797

9898
# Check warning is issued at end of simulation
99-
with pytest.warns(None) as recorded_warnings:
99+
with pytest.warns(UserWarning) as recorded_warnings:
100100
cons.on_simulation_end()
101101

102102
assert any_warnings_about_item_code(recorded_warnings)
@@ -479,35 +479,34 @@ def test_check_format_of_consumables_file():
479479

480480

481481
@pytest.mark.slow
482-
def test_every_declared_consumable_for_every_possible_hsi_using_actual_data():
482+
def test_every_declared_consumable_for_every_possible_hsi_using_actual_data(recwarn):
483483
"""Check that every item_code that is declared can be requested from a person at every district and facility_level.
484484
"""
485485

486486
sim = get_sim_with_dummy_module_registered(run=True)
487487
hs = sim.modules['HealthSystem']
488488
item_codes = hs.consumables.item_codes
489489

490-
with pytest.warns(None) as recorded_warnings:
491-
for month in range(1, 13):
492-
sim.date = Date(2010, month, 1)
493-
hs.consumables._refresh_availability_of_consumables(date=sim.date)
490+
for month in range(1, 13):
491+
sim.date = Date(2010, month, 1)
492+
hs.consumables._refresh_availability_of_consumables(date=sim.date)
494493

495-
for _district in sim.modules['Demography'].PROPERTIES['district_of_residence'].categories:
496-
# Change the district of person 0 (for whom the HSI is created.)
497-
sim.population.props.at[0, 'district_of_residence'] = _district
498-
for _facility_id in fac_ids:
499-
hsi_event = get_dummy_hsi_event_instance(
500-
module=sim.modules['DummyModule'],
501-
facility_id=_facility_id
502-
)
503-
for _item_code in item_codes:
504-
hsi_event.get_consumables(item_codes=_item_code)
494+
for _district in sim.modules['Demography'].PROPERTIES['district_of_residence'].categories:
495+
# Change the district of person 0 (for whom the HSI is created.)
496+
sim.population.props.at[0, 'district_of_residence'] = _district
497+
for _facility_id in fac_ids:
498+
hsi_event = get_dummy_hsi_event_instance(
499+
module=sim.modules['DummyModule'],
500+
facility_id=_facility_id
501+
)
502+
for _item_code in item_codes:
503+
hsi_event.get_consumables(item_codes=_item_code)
505504

506-
sim.modules['HealthSystem'].on_simulation_end()
505+
sim.modules['HealthSystem'].on_simulation_end()
507506

508507
# Check that no warnings raised or item_codes recorded as being not recogised.
509508
assert not sim.modules['HealthSystem'].consumables._not_recognised_item_codes
510-
assert not any_warnings_about_item_code(recorded_warnings)
509+
assert not any_warnings_about_item_code(recwarn)
511510

512511

513512
def test_get_item_code_from_item_name():

tests/test_core.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class TestLoadParametersFromDataframe:
5151
5252
No explicit tests for correct parsing of boolean because of how python evaluates truthiness
5353
"""
54-
def setup(self):
54+
def setup_method(self):
5555
class ParameterModule(Module):
5656
def __init__(self):
5757
super().__init__(name=None)
@@ -169,7 +169,7 @@ def test_bools(self):
169169

170170
class TestLoadParametersFromDataframe_Bools_From_Csv:
171171
"""Tests for the load_parameters_from_dataframe method, including handling of bools when loading from csv"""
172-
def setup(self):
172+
def setup_method(self):
173173
class ParameterModule(Module):
174174
def __init__(self):
175175
super().__init__(name=None)

tests/test_logging.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ def test_messages_lower_level(self, simulation_configuration, message_level):
137137

138138

139139
class TestConvertLogData:
140-
def setup(self):
140+
def setup_method(self):
141141
self.expected_output = {'item_1': 1, 'item_2': 2}
142142
self.logger = logging.getLogger('tlo.test.logger')
143143

tox.ini

+2-6
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ passenv =
2727
usedevelop = false
2828
deps =
2929
-r{toxinidir}/requirements/base.txt
30-
; Pin pytest version as some tests use features deprecated in v8
31-
; See https://github.com/UCL/TLOmodel/issues/1264
32-
pytest==7.4.4
30+
pytest
3331
pytest-cov
3432
commands =
3533
{posargs:pytest --cov --cov-report=term-missing -vv tests}
@@ -40,9 +38,7 @@ deps =
4038
pandas15: pandas==1.5.3
4139
pandas20: pandas==2.0.0
4240
pandas21: pandas==2.1.0
43-
; Pin pytest version as some tests use features deprecated in v8
44-
; See https://github.com/UCL/TLOmodel/issues/1264
45-
pytest==7.4.4
41+
pytest
4642
pytest-cov
4743

4844
[testenv:spell]

0 commit comments

Comments
 (0)