From cef94b2f73ad9d57d91641b56b5133833f461c94 Mon Sep 17 00:00:00 2001 From: F-G Fernandez <26927750+frgfm@users.noreply.github.com> Date: Fri, 19 Apr 2024 14:29:40 +0200 Subject: [PATCH] test(pytest): remove unnecessary await & async --- src/tests/test_security.py | 23 ++++++++++------------- src/tests/test_services.py | 12 ------------ 2 files changed, 10 insertions(+), 25 deletions(-) diff --git a/src/tests/test_security.py b/src/tests/test_security.py index eb69161..2634a07 100644 --- a/src/tests/test_security.py +++ b/src/tests/test_security.py @@ -7,24 +7,22 @@ from app.core.security import create_access_token, hash_password, verify_password -@pytest.mark.asyncio() -async def test_hash_password(): +def test_hash_password(): pwd1 = "my_password" - hash_pwd1 = await hash_password(pwd1) + hash_pwd1 = hash_password(pwd1) assert hash_pwd1 != pwd1 - assert hash_pwd1 != await hash_password(pwd1 + "bis") + assert hash_pwd1 != hash_password(pwd1 + "bis") # Check that it's non deterministic - assert hash_pwd1 != await hash_password(pwd1) + assert hash_pwd1 != hash_password(pwd1) -@pytest.mark.asyncio() -async def test_verify_password(): +def test_verify_password(): pwd1 = "my_password" - hash_pwd1 = await hash_password(pwd1) + hash_pwd1 = hash_password(pwd1) - assert await verify_password(pwd1, hash_pwd1) - assert not await verify_password("another_try", hash_pwd1) + assert verify_password(pwd1, hash_pwd1) + assert not verify_password("another_try", hash_pwd1) @pytest.mark.parametrize( @@ -34,9 +32,8 @@ async def test_verify_password(): ({"data": "my_data"}, None, settings.ACCESS_TOKEN_EXPIRE_MINUTES), ], ) -@pytest.mark.asyncio() -async def test_create_access_token(content, expires_minutes, expected_delta): - payload = await create_access_token(content, expires_minutes) +def test_create_access_token(content, expires_minutes, expected_delta): + payload = create_access_token(content, expires_minutes) after = datetime.utcnow() assert isinstance(payload, str) decoded_data = jwt.decode(payload, settings.SECRET_KEY, algorithms=[settings.JWT_ENCODING_ALGORITHM]) diff --git a/src/tests/test_services.py b/src/tests/test_services.py index 8635cc7..529b6c1 100644 --- a/src/tests/test_services.py +++ b/src/tests/test_services.py @@ -12,7 +12,6 @@ (249513553, 200, None, "frgfm/torch-cam"), ], ) -@pytest.mark.asyncio() def test_githubclient_get_repo(repo_id, status_code, status_detail, expected_name): github_client = GitHubClient() if isinstance(expected_name, str): @@ -32,7 +31,6 @@ def test_githubclient_get_repo(repo_id, status_code, status_detail, expected_nam (26927750, 200, None, "frgfm"), ], ) -@pytest.mark.asyncio() def test_githubclient_get_user(user_id, status_code, status_detail, expected_name): github_client = GitHubClient() if isinstance(expected_name, str): @@ -52,7 +50,6 @@ def test_githubclient_get_user(user_id, status_code, status_detail, expected_nam ("frgfm/torch-cam", 200, None, "README.md"), ], ) -@pytest.mark.asyncio() def test_githubclient_get_readme(repo_name, status_code, status_detail, expected_path): github_client = GitHubClient() if isinstance(expected_path, str): @@ -73,7 +70,6 @@ def test_githubclient_get_readme(repo_name, status_code, status_detail, expected ("frgfm/torch-cam", "CONTRIBUTING.md", 200, None), ], ) -@pytest.mark.asyncio() def test_githubclient_get_file(repo_name, file_path, status_code, status_detail): github_client = GitHubClient() if status_code // 100 == 2: @@ -94,7 +90,6 @@ def test_githubclient_get_file(repo_name, file_path, status_code, status_detail) ("frgfm/torch-cam", 200, None), ], ) -@pytest.mark.asyncio() def test_githubclient_list_pulls(repo_name, status_code, status_detail): github_client = GitHubClient() if status_code // 100 == 2: @@ -113,7 +108,6 @@ def test_githubclient_list_pulls(repo_name, status_code, status_detail): ("frgfm/torch-cam", 181, 200, None), ], ) -@pytest.mark.asyncio() def test_githubclient_list_comments_from_issue(repo_name, issue_number, status_code, status_detail): github_client = GitHubClient() if status_code // 100 == 2: @@ -132,7 +126,6 @@ def test_githubclient_list_comments_from_issue(repo_name, issue_number, status_c ("frgfm/Holocron", 279, 200, None), ], ) -@pytest.mark.asyncio() def test_githubclient_list_reviews_from_pull(repo_name, pull_number, status_code, status_detail): github_client = GitHubClient() if status_code // 100 == 2: @@ -151,7 +144,6 @@ def test_githubclient_list_reviews_from_pull(repo_name, pull_number, status_code ("frgfm/Holocron", 279, 200, None), ], ) -@pytest.mark.asyncio() def test_githubclient_list_review_comments_from_pull(repo_name, pull_number, status_code, status_detail): github_client = GitHubClient() if status_code // 100 == 2: @@ -170,7 +162,6 @@ def test_githubclient_list_review_comments_from_pull(repo_name, pull_number, sta ("frgfm/Holocron", 200, None), ], ) -@pytest.mark.asyncio() def test_githubclient_fetch_reviews_from_repo(repo_name, status_code, status_detail): github_client = GitHubClient() if status_code // 100 == 2: @@ -189,7 +180,6 @@ def test_githubclient_fetch_reviews_from_repo(repo_name, status_code, status_det ("frgfm/Holocron", 200, None), ], ) -@pytest.mark.asyncio() def test_githubclient_fetch_pull_comments_from_repo(repo_name, status_code, status_detail): github_client = GitHubClient() if status_code // 100 == 2: @@ -220,7 +210,6 @@ def test_githubclient_fetch_pull_comments_from_repo(repo_name, status_code, stat ), ], ) -@pytest.mark.asyncio() def test_githubclient_arrange_in_threads(comments, expected_output): assert GitHubClient.arrange_in_threads(comments) == expected_output @@ -231,7 +220,6 @@ def test_githubclient_arrange_in_threads(comments, expected_output): (lambda x: x**2, [1, 2, 3], [1, 4, 9]), ], ) -@pytest.mark.asyncio() def test_execute_in_parallel(func, arr, output): assert list(execute_in_parallel(func, arr, num_threads=1)) == output assert list(execute_in_parallel(func, arr, num_threads=2)) == output