Skip to content

Commit

Permalink
add more error cases to skip decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
catalinaperalta committed Oct 19, 2022
1 parent 0cadbad commit 90aba23
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions sdk/formrecognizer/azure-ai-formrecognizer/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,18 @@
# license information.
# --------------------------------------------------------------------------

import logging
import pytest
from functools import wraps
from azure.core.exceptions import HttpResponseError
import sys
from devtools_testutils import add_remove_header_sanitizer, add_general_regex_sanitizer, add_oauth_response_sanitizer, add_body_key_sanitizer, test_proxy

# Ignore async tests for Python < 3.6
collect_ignore_glob = []
if sys.version_info < (3, 6):
collect_ignore_glob.append("*_async.py")
from devtools_testutils import (
add_remove_header_sanitizer,
add_general_regex_sanitizer,
add_oauth_response_sanitizer,
add_body_key_sanitizer,
test_proxy,
)

@pytest.fixture(scope="session", autouse=True)
def add_sanitizers(test_proxy):
Expand Down Expand Up @@ -67,6 +69,18 @@ def wrapper(*args, **kwargs):
try:
return f(*args, **kwargs)
except HttpResponseError as error:
logger = logging.getLogger("azure")
if "Invalid request".casefold() in error.message.casefold():
pytest.mark.skip("flaky service response")
pytest.mark.skip("flaky service response: {}".format(error))
logger.debug("flaky service response: {}".format(error))
elif "Generic error".casefold() in error.message.casefold():
pytest.mark.skip("flaky service response: {}".format(error))
logger.debug("flaky service response: {}".format(error))
elif "Timeout" in error.message.casefold():
pytest.mark.skip("flaky service response: {}".format(error))
logger.debug("flaky service response: {}".format(error))
elif "InvalidRequest" in error.message.casefold():
pytest.mark.skip("flaky service response: {}".format(error))
logger.debug("flaky service response: {}".format(error))

return wrapper

0 comments on commit 90aba23

Please sign in to comment.