JamesHutchison / pytest-hot-reloading

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

Fixture updates don't seem to work #65

Closed JamesHutchison closed 7 months ago

JamesHutchison commented 8 months ago

The hot reloading functionality doesn't seem to work for fixtures. For example, if you have a fixture that uses a fixture that doesn't exist (anymore), and you delete that fixture reference, it'll continue to error and look for that missing fixture until you restart the daemon

Here's the changes being updated:

Update tests.invite_fixtures.main_user_self_contact_invite @L19
Update tests.invite_fixtures.main_user_to_other_user_invite @L44
Update tests.invite_fixtures.main_user_expired_invite @L68

Here's the updated fixture that no longer references access_invite_repo erroring:

  @pytest.fixture()
  async def main_user_self_contact_invite(
      main_user: UserBundle,
  ) -> SQLAccessInvite:
      system_key = await SystemKeyManager().create_system_key(
          main_user.user.id, TargetComponent.CONTACT, ["all"]
      )
      invitee_name = "anyone"
      invitee_org = "any org"
      access_invite = SQLAccessInvite(
          created_by=main_user.user.id,
          target_user_id=main_user.user.id,
          system_key_id=system_key.id,
          invitee_name=invitee_name,
          invitee_org=invitee_org,
          redemption_limit=1,
          expires=datetime.datetime.utcnow() + datetime.timedelta(days=7),
          target_component=TargetComponent.CONTACT,
          target_subcomponents=["all"],
      )
      await AccessInviteRepository().create_access_invite(access_invite)
      return access_invite
E       fixture 'access_invite_repo' not found

The likely reason is that the fixtures are already loaded in memory so updating the code objects doesn't do anything.

Updating the fixtures used by a test also do not seem to benefit from hot reloading. If I remove a fixture and then run a test that used it, then remove the references to the fixture in the test, it still errors because the fixture doesn't exist.

JamesHutchison commented 8 months ago

Another way this may manifest is when adding a fixture. You'll get an error saying the test function is missing a positional argument.