JamesHutchison / pytest-hot-reloading

A hot reloading pytest daemon, implemented as a plugin
MIT License
86 stars 2 forks source link

Fix wrong fixture behavior due to cached fixtures and conftest not being watched #67

Closed JamesHutchison closed 8 months ago

JamesHutchison commented 8 months ago

This addresses #65

There are a couple issues around fixtures that this addresses.

The fixture logic and dependencies not updating were observed as occurring due to conftest files not being watched. The automatic file watching applied to tests but not the conftest files used by tests. This adds automatic watching of conftest files, which can be disabled with PYTEST_DAEMON_DO_NOT_AUTOWATCH_FIXTURES / --daemon-do-not-autowatch-fixtures

The other issue was that the session caching was resulting in stale fixture references in test functions. This adds logic to clear the session cache if jurigged updates the signature of a test function.

Adds env variable - PYTEST_DAEMON_USE_WATCHMAN which determines whether to use watchman or polling for filesystem updates.

JamesHutchison commented 8 months ago

Randomly reproducing the CI issues so there appears to be more to it

JamesHutchison commented 8 months ago

Running in a dev container, it usually passes

Running in the CI it seems to always fail

Adding delays and retries not mitigating issue on CI. Adding delays seemed to help on dev container but maybe it didn't. Retries not helping seems to imply that if its a race condition, things are getting "cemented".

Odd that jurigged acknowledges changes, test run indicates that its not using a cached session, but seeing the error when things were cached.

JamesHutchison commented 8 months ago

Github CI must be using a cached network mount that results in signals working but stale file read data. Moving to temp directory (which won't use mount and should have predictable IO), which I contemplating doing originally, seems to have fixed the CI issue. It's not clear to me why errors showed the updated version of the function but even with excessive delays the hot reloader was still loading in a stale version.

JamesHutchison commented 7 months ago

Related to #16 because this adds the env variable PYTEST_DAEMON_USE_WATCHMAN