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

Feature/refactor backend tests env dependency #72

Conversation

harry-bedford
Copy link
Collaborator

Description

This PR removes the dependency that our tests have on the .env file. This arose from certain imports causing files to run that were making use of env variables. My understanding is that this is a compile time issue. So, the change has been to make sure that wherever the env variables are used, it is at run time, and not compile time. For example, using getters for the agents instead of instantiating them in the init file.

Changelog

  • Decouple unit test dependency to .env file
  • Delete creation of .env file in ci

Copy link
Collaborator

@hsauve-scottlogic hsauve-scottlogic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great Harry! I've asked a couple of questions, thanks

return {"name": agent.name, "description": agent.description}


agents = [DatastoreAgent(config.datastore_agent_llm), MathsAgent(config.maths_agent_llm)]
agents_details = [get_agent_details(agent) for agent in agents]
def get_question_agents() -> List[Agent]:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if the name question_agents is too vague, could it be something like available_agents?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah I like available_agents, will change to that

@@ -24,8 +26,9 @@ def test_get_agent_for_task_no_agent_found(mocker):

def test_get_agent_for_task_agent_found(mocker):
plan = {"agent_name": mock_agent_name}
mocker.patch("src.router.agents", mock_agents)
mocker.patch("src.router.llm", mock_model)
mocker.patch("src.router.get_llm", return_value=mock_model)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just so I understand, we're not actually using the get_llm function which needs the env file, instead we're instantiating a mock value for llm with 'mockllm' on line 8?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, this is a little confusing, I'll change. Yes, the test is mocking out get_llm so that whenever it is called during the test, the mock_model on line 8 will always be returned. The confuding part is that line 8 is actually using get_llm to get the mock model. It would make more sense if line 8 was:

mock_model = MockLLM()

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes okay, thanks that makes sense

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@harryBedfordSL - I am unable to test it locally. Even after renaming the .env file locally, all the tests are running in my other branch and according to you they should fail without all the changes in this PR, so not sure how to test this one.

Copy link
Collaborator

@gaganahluwalia gaganahluwalia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy with the changes.

@harry-bedford harry-bedford merged commit 7789cea into release/sum-my-subscriptions Jun 21, 2024
3 checks passed
@harry-bedford harry-bedford deleted the feature/refactor-backend-tests-env-dependency branch June 21, 2024 10:00
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

Successfully merging this pull request may close these issues.

3 participants