Your logic is rather.. involved. If you want to test if at least one of those variables is not None
, then use any()
:
debug.assert(any(v is not None for v in (data, id, time, group)))
any()
iterates over the v is not None for v in (data, id, time, group)
generator expression and returns True
the moment it encounters a True
result. This means that if data
is not None
, then the other 3 values are not tested. If, however, all 4 values are None
then any()
returns False
and the assertion test fails.
I don't know what framework you are using to test assertions, I assumed there would be a .assert()
method.
When catching an assertion failure exception, I would not catch Exception
, that's way too broad and will mask bugs. A test framework will raise specific exceptions to signal assertion failure, such as the built in AssertionError
. Catch that specific exception instead, if you must.