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

make it easier to mock instance events for sensor tests #3845

Open
sryza opened this issue Mar 12, 2021 · 0 comments
Open

make it easier to mock instance events for sensor tests #3845

sryza opened this issue Mar 12, 2021 · 0 comments

Comments

@sryza
Copy link
Contributor

sryza commented Mar 12, 2021

Use Case

The best way right now to test an asset sensor required mock.patch:

@mock.patch("dagster.core.instance.DagsterInstance.events_for_asset_key")
def test_first_events(mock_events_for_asset_key):
    mock_events_for_asset_key.side_effect = get_mock_events_for_asset_key(
        [("comments", 1), ("stories", 2)]
    )

    with tempfile.TemporaryDirectory() as tmpdir_path:
        context = SensorExecutionContext(
            instance_ref=InstanceRef.from_dir(tmpdir_path),
            last_run_key=None,
            last_completion_time=None,
        )
        requests = story_recommender_sensor.get_execution_data(context)
        assert len(requests) == 1
        assert requests[0].run_key == "1|2"

Ideas of Implementation

create_sensor_context(instance=instance_with_events(events))

Additional Info


Message from the maintainers:

Excited about this feature? Give it a 👍. We factor engagement into prioritization.

@yuhan yuhan added this to Untriaged in Practitioner via automation Apr 13, 2021
@yuhan yuhan added the test label May 14, 2021
@yuhan yuhan added this to Backlog in Practitioner May 14, 2021
@yuhan yuhan removed the core label Aug 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Development

No branches or pull requests

3 participants