gugarosa / opytimizer

🐦 Opytimizer is a Python library consisting of meta-heuristic optimization algorithms.
https://opytimizer.readthedocs.io
Apache License 2.0
604 stars 41 forks source link

[REG] Strange testing pattern #6

Closed lzfelix closed 5 years ago

lzfelix commented 5 years ago

Hi, while browsing through the tests I found the following construction several times. Can you please explain the rationale behind it?

try:
    new_optimizer.hyperparams = 1  # (1)
except:
    new_optimizer.hyperparams = {
        'w': 1.5
    }

If you're executing (1) hoping for it to fail, then that should be asserted as well.

Thanks, Felix

gugarosa commented 5 years ago

Hello! I hope everything is all right!

As we have discussed yesterday, it is just a trick to raise the exception and make use of the corresponding line, for asserting the line while running the coverage tests.

Nevertheless, we will further investigate if the pytest.exceptions module is helpful to design this approach, as suggested by you.

Best regards, Gustavo.