Tips and TricksΒΆ
To save typing and make your tests more readable, loop over array elements rather than indices when possible. If you do also need the index, you can use
enumerate()to get both without having to loop explicitly. For example:# loop over elements for profiles_1d in ids.profiles_1d: assert profiles_1d.ion.has_value for ion in profiles_1d.ion: assert ion.element.has_value for element in ion.element: assert element.a.has_value # loop over elements with index using enumerate for i, profiles_1d in enumerate(ids.profiles_1d): assert profiles_1d.ion.has_value ... # rest of codeYou can immediately check whether all values of an array adhere to a condition without building a loop. This is more efficient because it uses
numpyoptimized C code in the background.assert -1.7e7 < ids.global_quantities.ip <= 0
Last update:
2025-06-05