-
Notifications
You must be signed in to change notification settings - Fork 300
Closed
Labels
Description
📰 Custom Issue
We have some tests for NetCDF loading that are created by using setattr on the test class:
iris/lib/iris/tests/unit/fileformats/nc_load_rules/actions/test__hybrid_formulae.py
Lines 242 to 278 in 0a0cb87
| # Add in tests methods to exercise each (supported) vertical coordinate type | |
| # individually. | |
| # NOTE: hh.CF_COORD_VERTICAL lists all the valid types, but we don't yet | |
| # support all of them. | |
| _SUPPORTED_FORMULA_TYPES = ( | |
| # NOTE: omit "atmosphere_hybrid_height_coordinate" : our basic testcase | |
| "atmosphere_sigma_coordinate", | |
| "atmosphere_hybrid_sigma_pressure_coordinate", | |
| "ocean_sigma_z_coordinate", | |
| "ocean_sigma_coordinate", | |
| "ocean_s_coordinate", | |
| "ocean_s_coordinate_g1", | |
| "ocean_s_coordinate_g2", | |
| ) | |
| for hybrid_type in _SUPPORTED_FORMULA_TYPES: | |
| def construct_inner_func(hybrid_type): | |
| term_names = hh.CF_COORD_VERTICAL[hybrid_type] | |
| def inner(self): | |
| result = self.run_testcase( | |
| formula_root_name=hybrid_type, term_names=term_names | |
| ) | |
| self.check_result( | |
| result, factory_type=hybrid_type, formula_terms=term_names | |
| ) | |
| return inner | |
| # Note: use an intermediate function to generate each test method, simply to | |
| # generate a new local variable for 'hybrid_type' on each iteration. | |
| # Otherwise all the test methods will refer to the *same* 'hybrid_type' | |
| # variable, i.e. the loop variable, which does not work ! | |
| method_name = f"test_{hybrid_type}_coord" | |
| setattr( | |
| Test__formulae_tests, method_name, construct_inner_func(hybrid_type) | |
| ) |
nose does not seem to be discovering these. They run fine if you run the module directly, and they are also discovered by pytest. So this issue would be solved by implementing #3835 🙂