MatthewFlamm / pytest-homeassistant-custom-component

Package to automatically extract testing plugins from Home Assistant for custom component testing
MIT License
66 stars 10 forks source link

Avoid recursion in replacing socket with GuardedSocket #114

Closed make-all closed 2 years ago

make-all commented 2 years ago

In a project with a lot of tests, a recursion error is eventually raised due to the socket being replaced with a GuardedSocket at the start of each test, but this is not undone after the test.

Add a check and if the socket has already been replaced, skip doing it again.

MatthewFlamm commented 2 years ago

Thanks for the PR!

This library automatically creates this file from homeassistant/core. Why is this not needed in the homeassistant tests? I am very hesitant to add anything custom here that isn't explicitly required for custom integrations.

make-all commented 2 years ago

Maybe the issue is from upstream, and they have some other way of avoiding it. I'll see if I can identify why they are not hitting it (they must have over 1000 tests, I am hitting it on test 934), maybe there is a better change elsewhere in non-generated code, or in my tests.

MatthewFlamm commented 2 years ago

Thanks. If there is indeed some special that this has to be handled for custom integrations, we need to figure out a way that doesn't involve modifying a fixture from homeassistant. We could add our own or add one that wraps a homeassistant one.

make-all commented 2 years ago

I've filed an issue report upstream https://github.com/home-assistant/core/issues/69724 I think the only reason they are avoiding it is they have enough tests marked as socket_enabled to reset things before the recursion limit is reached. They have broken their tests up into 6 stages, but there are still over 3000 tests per stage, so they should be hitting the problem if no tests are enabling sockets.

make-all commented 2 years ago

Latest upstream seems to have fixed the issue.