pyfrc icon indicating copy to clipboard operation
pyfrc copied to clipboard

[BUG] Cleanup doesn't occur correctly if tests fail

Open virtuald opened this issue 1 year ago • 1 comments

I think what's happening is that when pytest is processing the exception, the traceback holds references to local objects (including the robot) and so the robot and related objects (in some cases) are never fully freed, so when the hal handles and other things are cleared at the end of the test those objects are all orphaned. Several solutions come to mind:

  • find a pytest hook that runs when we need it to happen and use that instead of at the end of the robot fixture
  • Run the resets at the beginning of the next function instead
  • We can technically run each tests in a new process now since the CLI doesn't have to import the robot code.. that would not be ideal, but many of these sorts of issues might disappear.

I believe this is causing https://github.com/robotpy/robotpy-navx/issues/30, but I don't have conclusive proof.

virtuald avatar Jan 28 '24 06:01 virtuald

I think what's happening is that when pytest is processing the exception, the traceback holds references to local objects (including the robot) and so the robot and related objects (in some cases) are never fully freed, so when the hal handles and other things are cleared at the end of the test those objects are all orphaned.

I concur here.

We can technically run each tests in a new process now since the CLI doesn't have to import the robot code.

I've used pytest-forked previously, but that doesn't work on Windows.

Maybe it's time to solve #212 and use pytest-xdist?

auscompgeek avatar Jan 28 '24 06:01 auscompgeek