Met4FoF / agentMET4FOF

Metrological Agent-based system (MET4FOF project)
Other
22 stars 8 forks source link

Check test suite execution #234

Closed gertjan123 closed 3 years ago

gertjan123 commented 3 years ago

I'm wondering if the tests are really executed, as there is no "if name == 'main':" section in the tests. Maybe only the function definitions are loaded, but not really executed.

If all goes well, I'm wondering why I had this problem in my redundancy tests using PyCharm.

BjoernLudwigPTB commented 3 years ago

The tests do get executed by pytest via tox. You can check the execution results in the pipelines output i.e. here for release v0.8.0.

Occasionally the tests fail though, without us knowing why. A single rerun usually results in the tests passing again. Seems as if some randomness sometimes causes issues.

BjoernLudwigPTB commented 3 years ago

If all goes well, I'm wondering why I had this problem in my redundancy tests using PyCharm.

@gertjan123 What problem are you referring to?

gertjan123 commented 3 years ago

I think you refer to: agentMET4FOF_tutorials/tutorial_1_generator_agent.py 18 2 2 1 85% i.e. some code of this file is used somehow in the tests.

I'm referring to the following:

Based on what I see in Pycharm following might happen:

pytest runs test_tutorials.py:

It loads demonstrate_generator_agent_use from agentMET4FOF_tutorials.tutorial_1_generator_agent:

from agentMET4FOF_tutorials.tutorial_1_generator_agent import ( demonstrate_generator_agent_use as tut1, )

It defines a function test_tutorial_1() using tut1() from agentMET4FOF_tutorials.tutorial_1_generator_agent:

def test_tutorial_1(): """Test executability of tutorial_1_generator_agent.""" tut1().shutdown()

But as there is no line:

if name == "main": test_tutorial_1()

the function test_tutorial_1() is never really called and executed, it's only defined and loaded.

At least when I executed the test_tutorials script in PyCharm nothing visible happened (no agent network starting up). Only when I added this clause, things started happening.

You could implement a run-time error in the agent framework and see if it gets catched with the current code.

(Unless you are convinced that it is nonsense what I'm writing here.)

BjoernLudwigPTB commented 3 years ago

(Unless you are convinced that it is nonsense what I'm writing here.)

Actually you are missing something very important here. Try executing $ pytest from the commandline in your repo's root folder. That really executes all tests in any of the subfolders. There is no need for any if name == 'main': for pytest to execute the tests. For more information refer to the official pytest docs… or let's schedule a short video chat to sort out any further issues. :wink:

gertjan123 commented 3 years ago

Indeed, you are right! Thanks for the explication and the link to the documentation! I still have a lot to learn, and studying the repository and your answers both help a lot.