Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plugin loading order with Syrupy #198

Open
wbyoung opened this issue Jul 29, 2024 · 3 comments
Open

Plugin loading order with Syrupy #198

wbyoung opened this issue Jul 29, 2024 · 3 comments

Comments

@wbyoung
Copy link

wbyoung commented Jul 29, 2024

I have encountered a situation where tests pass locally and fail in CI because the snapshots generated by Syrupy can't be found. I've found a solution to this issue which is to run the tests as pytest -p syrupy (or adding it to addopts under [tool:pytest] in my config).

I'm guessing that if Syrupy is loaded second, that the options to configure the directory override what's setup by pytest_homeassistant_custom_component, but I can't be sure.

I don't know if there's a way to configure this to say it must be loaded after Syrupy, but that would probably be good. If not, maybe it may be useful to document it.

@MatthewFlamm
Copy link
Owner

I'm guessing that if Syrupy is loaded second, that the options to configure the directory override what's setup by pytest_homeassistant_custom_component, but I can't be sure.

This seems very plausible, see

https://github.com/home-assistant/core/blob/1f488b00f85003a17752b5c15f86495c029bc382/tests/conftest.py#L1856-L1859

where homeassistant uses the same name of the fixture as syrupy itself. Given that this package is a plugin whereas the homeassistant tests conftest.py is not a plugin, this could explain the difference why homeassistant CI does not have this problem. It would be ideal if we could fix it in this package somehow, but I'm not sure it is possible.

Your fix is mentioned in this thread pytest-dev/pytest#935, which still seems unresolved. I'm not sure we can do anything about it other than putting it in the README for now.

@wbyoung
Copy link
Author

wbyoung commented Jul 29, 2024

Yup, I was reading that thread earlier. Your assessment seems in line with the (little) I know about this. Putting it in the Readme seems like a good resolution.

@zxdavb
Copy link

zxdavb commented Sep 10, 2024

I have encountered a situation where tests pass locally and fail in CI because the snapshots generated by Syrupy can't be found.

I am getting the same symptom, but also it fails because the custom serializer is not used (e.g. timestamps are not set to <ANY>).

The workaround that works for me is to duplicate the snapshot fixture in my CC's conftest.py:

from pytest_homeassistant_custom_component.syrupy import HomeAssistantSnapshotExtension
from syrupy.assertion import SnapshotAssertion

   ...

@pytest.fixture
def snapshot(snapshot: SnapshotAssertion) -> SnapshotAssertion:
    """Return snapshot assertion fixture with the Home Assistant extension."""
    return snapshot.use_extension(HomeAssistantSnapshotExtension)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants