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

test: fix Session mocking #314

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 11 additions & 15 deletions tests/cli/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,26 +39,22 @@ def mock_specified_session_name(specified_session_name):


@pytest.fixture
@patch("goose.cli.session.create_exchange", name="mock_exchange")
@patch("goose.cli.session.load_profile", name="mock_load_profile")
@patch("goose.cli.session.SessionNotifier", name="mock_session_notifier")
@patch("goose.cli.session.load_provider", name="mock_load_provider")
def create_session_with_mock_configs(
mock_load_provider,
mock_session_notifier,
mock_load_profile,
mock_exchange,
mock_sessions_path,
exchange_factory,
profile_factory,
):
mock_load_provider.return_value = "provider"
mock_session_notifier.return_value = MagicMock()
mock_load_profile.return_value = profile_factory()
mock_exchange.return_value = exchange_factory()

def create_session(session_attributes: dict = {}):
return Session(**session_attributes)
with (
patch("goose.cli.session.create_exchange", name="mock_exchange") as mock_exchange,
patch("goose.cli.session.load_profile", name="mock_load_profile") as mock_load_profile,
patch("goose.cli.session.SessionNotifier", name="mock_session_notifier") as mock_session_notifier,
patch("goose.cli.session.load_provider", name="mock_load_provider") as mock_load_provider,
):
mock_load_provider.return_value = "provider"
mock_session_notifier.return_value = MagicMock()
mock_load_profile.return_value = profile_factory()
mock_exchange.return_value = exchange_factory()
return Session(**session_attributes)

return create_session

Expand Down
Loading