Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Fix side-effects generated by pytest-django's autouse fixtures

NyanKiyoshi135f91983c9e
diff --git a/.gitignore b/.gitignore
index c5190bdbc7..aa60042615 100644
--- a/.gitignore
+++ b/.gitignore
@@ -35,3 +35,6 @@ dist/
webpack-bundle.json
/templates/templated_email/compiled/*
!/templates/templated_email/compiled/.gitkeep
+
+# Exported results file
+django-queries-results.html
diff --git a/tests/api/test_checkout_bench.py b/tests/api/test_checkout_bench.py
index 9acd050809..86813643ef 100644
--- a/tests/api/test_checkout_bench.py
+++ b/tests/api/test_checkout_bench.py
@@ -62,8 +62,8 @@ def checkout_with_charged_payment(checkout_with_billing_address):
@pytest.mark.django_db
-def test_create_checkout(api_client, graphql_address_data, variant):
[email protected]_queries(autouse=False)
+def test_create_checkout(api_client, graphql_address_data, variant, count_queries):
query = """
fragment Price on TaxedMoney {
gross {
@@ -223,9 +223,14 @@ def test_create_checkout(api_client, graphql_address_data, variant):
@pytest.mark.django_db
[email protected]_queries(autouse=False)
def test_add_shipping_to_checkout(
- api_client, graphql_address_data, variant, checkout_with_variant, shipping_method
+ api_client,
+ graphql_address_data,
+ variant,
+ checkout_with_variant,
+ shipping_method,
+ count_queries,
):
query = """
fragment Price on TaxedMoney {
@@ -384,9 +389,9 @@ def test_add_shipping_to_checkout(
@pytest.mark.django_db
[email protected]_queries(autouse=False)
def test_add_billing_address_to_checkout(
- api_client, graphql_address_data, checkout_with_shipping_method
+ api_client, graphql_address_data, checkout_with_shipping_method, count_queries
):
query = """
fragment Price on TaxedMoney {
@@ -545,9 +550,9 @@ def test_add_billing_address_to_checkout(
@pytest.mark.django_db
[email protected]_queries(autouse=False)
def test_checkout_payment_charge(
- api_client, graphql_address_data, checkout_with_billing_address
+ api_client, graphql_address_data, checkout_with_billing_address, count_queries
):
query = """
mutation createPayment($input: PaymentInput!, $checkoutId: ID!) {
@@ -575,8 +580,8 @@ def test_checkout_payment_charge(
@pytest.mark.django_db
-def test_complete_checkout(api_client, checkout_with_charged_payment):
[email protected]_queries(autouse=False)
+def test_complete_checkout(api_client, checkout_with_charged_payment, count_queries):
query = """
mutation completeCheckout($checkoutId: ID!) {
checkoutComplete(checkoutId: $checkoutId) {
diff --git a/tests/api/test_homepage_bench.py b/tests/api/test_homepage_bench.py
index c8ac4c5b9b..71170b68ea 100644
--- a/tests/api/test_homepage_bench.py
+++ b/tests/api/test_homepage_bench.py
@@ -4,8 +4,8 @@ from tests.api.utils import get_graphql_content
@pytest.mark.django_db
-def test_retrieve_main_menu(api_client):
[email protected]_queries(autouse=False)
+def test_retrieve_main_menu(api_client, count_queries):
query = """
fragment MainMenuSubItem on MenuItem {
id
@@ -62,8 +62,8 @@ def test_retrieve_main_menu(api_client):
@pytest.mark.django_db
-def test_retrieve_secondary_menu(api_client):
[email protected]_queries(autouse=False)
+def test_retrieve_secondary_menu(api_client, count_queries):
query = """
fragment SecondaryMenuSubItem on MenuItem {
id
@@ -110,8 +110,8 @@ def test_retrieve_secondary_menu(api_client):
@pytest.mark.django_db
-def test_retrieve_shop(api_client):
[email protected]_queries(autouse=False)
+def test_retrieve_shop(api_client, count_queries):
query = """
query getShop {
shop {
@@ -142,8 +142,8 @@ def test_retrieve_shop(api_client):
@pytest.mark.django_db
-def test_retrieve_product_list(api_client):
[email protected]_queries(autouse=False)
+def test_retrieve_product_list(api_client, count_queries):
query = """
query ProductsList {
shop {
diff --git a/tests/api/test_payment_bench.py b/tests/api/test_payment_bench.py
index f29134fb57..c1458d7052 100644
--- a/tests/api/test_payment_bench.py
+++ b/tests/api/test_payment_bench.py
@@ -1,12 +1,16 @@
import pytest
+from django.conf import settings
+
+from tests.api.utils import get_graphql_content
@pytest.mark.django_db
-def test_get_payment_token(api_client):
[email protected]_queries(autouse=False)
+def test_get_payment_token(count_queries, api_client):
query = """
query getPaymentToken($gateway: GatewaysEnum!) {
paymentClientToken(gateway: $gateway)
}
"""
- assert query is not None # so flake stops being upset about the unused variable
+ variables = {"gateway": settings.DUMMY.upper()}
+ get_graphql_content(api_client.post_graphql(query, variables))