-
Notifications
You must be signed in to change notification settings - Fork 175
Fix pytest-asyncio deprecation warning by setting default loop scope #4802
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
Open
CodeVishal-17
wants to merge
16
commits into
microsoft:main
Choose a base branch
from
CodeVishal-17:fix/pytest-asyncio-deprecation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
63074a3
fix: set asyncio_default_fixture_loop_scope to avoid pytest warning
CodeVishal-17 e8e21a6
Fix pytest-asyncio v1.x async fixture usage
CodeVishal-17 2ef08bf
Fix pytest-asyncio deprecation by enforcing strict mode and sync fixt…
CodeVishal-17 02589d9
Merge branch 'main' into fix/pytest-asyncio-deprecation
CodeVishal-17 e4d68f7
Remove remaining pytest_asyncio fixtures and use sync pytest fixtures
CodeVishal-17 9ed9356
Fix remaining fixtures for pytest-asyncio strict mode
CodeVishal-17 f8a3815
Merge branch 'main' into fix/pytest-asyncio-deprecation
CodeVishal-17 435a77f
Add Bandit security scanning to PR validation workflow
CodeVishal-17 cc2c3e6
Remove Bandit config and CI steps from pytest-asyncio fix PR
CodeVishal-17 85500c9
Fix AsyncClient fixture lifecycle for pytest-asyncio strict mode
CodeVishal-17 e6164c6
Resolve merge conflict in conftest.py
CodeVishal-17 8b1de07
Merge branch 'main' into fix/pytest-asyncio-deprecation
CodeVishal-17 0d21f8c
Mark airlock route tests as asyncio
CodeVishal-17 90fcea4
Merge branch 'fix/pytest-asyncio-deprecation' of https://github.com/C…
CodeVishal-17 4bbf729
Remove unrelated CI Python setup from pytest-asyncio fix
CodeVishal-17 61b6e12
Merge branch 'main' into fix/pytest-asyncio-deprecation
CodeVishal-17 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| [pytest] | ||
| filterwarnings = | ||
| error | ||
| asyncio_mode = strict | ||
| asyncio_default_fixture_loop_scope = function | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,8 @@ | ||
| import time | ||
| import pytest | ||
| import pytest_asyncio | ||
|
|
||
| pytestmark = pytest.mark.asyncio | ||
|
|
||
| from mock import patch | ||
| from fastapi import status | ||
| from azure.core.exceptions import HttpResponseError | ||
|
|
@@ -17,7 +19,6 @@ | |
| from models.domain.operation import Operation | ||
| from resources import strings | ||
| from services.authentication import get_current_workspace_owner_or_researcher_user, get_current_workspace_owner_or_researcher_user_or_airlock_manager, get_current_airlock_manager_user | ||
| pytestmark = pytest.mark.asyncio | ||
|
|
||
|
|
||
| WORKSPACE_ID = "abc000d3-82da-4bfc-b6e9-9a7853ef753e" | ||
|
|
@@ -127,18 +128,31 @@ def inner(): | |
|
|
||
|
|
||
| class TestAirlockRoutesThatRequireOwnerOrResearcherRights(): | ||
| @pytest_asyncio.fixture(autouse=True, scope='class') | ||
| @pytest.fixture(autouse=True, scope="class") | ||
| def log_in_with_researcher_user(self, app, researcher_user): | ||
| app.dependency_overrides[get_current_workspace_owner_or_researcher_user] = researcher_user | ||
| app.dependency_overrides[get_current_workspace_owner_or_researcher_user_or_airlock_manager] = researcher_user | ||
| with patch("api.routes.airlock.AirlockRequestRepository.create_airlock_request_item", return_value=sample_airlock_request_object()), \ | ||
| patch("api.routes.workspaces.OperationRepository.resource_has_deployed_operation"), \ | ||
| patch("api.routes.airlock.AirlockRequestRepository.save_item"), \ | ||
| patch("api.dependencies.workspaces.WorkspaceRepository.get_workspace_by_id"), \ | ||
| patch("services.aad_authentication.AzureADAuthorization.get_workspace_user_emails_by_role_assignment", return_value={"WorkspaceResearcher": ["[email protected]"], "WorkspaceOwner": ["[email protected]"], "AirlockManager": ["[email protected]"]}): | ||
| with patch( | ||
| "api.routes.airlock.AirlockRequestRepository.create_airlock_request_item", | ||
| return_value=sample_airlock_request_object(), | ||
| ), patch( | ||
| "api.routes.workspaces.OperationRepository.resource_has_deployed_operation" | ||
| ), patch( | ||
| "api.routes.airlock.AirlockRequestRepository.save_item" | ||
| ), patch( | ||
| "api.dependencies.workspaces.WorkspaceRepository.get_workspace_by_id" | ||
| ), patch( | ||
| "services.aad_authentication.AzureADAuthorization.get_workspace_user_emails_by_role_assignment", | ||
| return_value={ | ||
| "WorkspaceResearcher": ["[email protected]"], | ||
| "WorkspaceOwner": ["[email protected]"], | ||
| "AirlockManager": ["[email protected]"], | ||
| }, | ||
| ): | ||
| yield | ||
| app.dependency_overrides = {} | ||
|
|
||
|
|
||
| # [GET] /workspaces/{workspace_id}/requests} | ||
| @patch("api.routes.airlock.AirlockRequestRepository.get_airlock_requests", return_value=[]) | ||
| async def test_get_all_airlock_requests_by_workspace_returns_200(self, _, app, client): | ||
|
|
@@ -303,17 +317,24 @@ async def test_get_airlock_container_link_returned_as_expected(self, get_airlock | |
|
|
||
|
|
||
| class TestAirlockRoutesThatRequireAirlockManagerRights(): | ||
| @pytest_asyncio.fixture(autouse=True, scope='class') | ||
| @pytest.fixture(autouse=True, scope="class") | ||
| def log_in_with_airlock_manager_user(self, app, airlock_manager_user): | ||
| app.dependency_overrides[get_current_airlock_manager_user] = airlock_manager_user | ||
| app.dependency_overrides[get_current_workspace_owner_or_researcher_user_or_airlock_manager] = airlock_manager_user | ||
| with patch("services.airlock.AirlockRequestRepository.create_airlock_request_item", return_value=sample_airlock_request_object()), \ | ||
| patch("api.routes.workspaces.OperationRepository.resource_has_deployed_operation"), \ | ||
| patch("services.airlock.AirlockRequestRepository.save_item"), \ | ||
| patch("api.dependencies.workspaces.WorkspaceRepository.get_workspace_by_id"): | ||
| with patch( | ||
| "services.airlock.AirlockRequestRepository.create_airlock_request_item", | ||
| return_value=sample_airlock_request_object(), | ||
| ), patch( | ||
| "api.routes.workspaces.OperationRepository.resource_has_deployed_operation" | ||
| ), patch( | ||
| "services.airlock.AirlockRequestRepository.save_item" | ||
| ), patch( | ||
| "api.dependencies.workspaces.WorkspaceRepository.get_workspace_by_id" | ||
| ): | ||
| yield | ||
| app.dependency_overrides = {} | ||
|
|
||
|
|
||
| # [POST] /workspaces/{workspace_id}/requests/{airlock_request_id}/review | ||
| @patch("services.airlock.AirlockRequestRepository.read_item_by_id", return_value=sample_airlock_request_object(status=AirlockRequestStatus.InReview)) | ||
| @patch("services.airlock.AirlockRequestRepository.create_airlock_review_item", return_value=sample_airlock_review_object()) | ||
|
|
@@ -463,14 +484,15 @@ async def test_post_revoke_airlock_request_missing_reason_returns_422(self, _, a | |
|
|
||
| class TestAirlockRoutesPermissions(): | ||
|
|
||
| @pytest_asyncio.fixture() | ||
| @pytest.fixture() | ||
| def log_in_with_user(self, app): | ||
| def inner(user): | ||
| app.dependency_overrides[get_current_workspace_owner_or_researcher_user] = user | ||
| app.dependency_overrides[get_current_airlock_manager_user] = user | ||
| app.dependency_overrides[get_current_workspace_owner_or_researcher_user_or_airlock_manager] = user | ||
| return inner | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("role", (role for role in get_required_roles(endpoint=create_draft_request))) | ||
| @patch("api.routes.workspaces.OperationRepository.resource_has_deployed_operation") | ||
| @patch("api.dependencies.workspaces.WorkspaceRepository.get_workspace_by_id", return_value=sample_workspace(WORKSPACE_ID)) | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.