Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zanieb committed Apr 4, 2023
1 parent 0af0234 commit ea2d871
Showing 1 changed file with 25 additions and 50 deletions.
75 changes: 25 additions & 50 deletions tests/test_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,18 +512,14 @@ def test_does_not_raise_when_logger_outside_of_run_context_with_default_setting(
self,
logger,
):
try:
with pytest.warns(
UserWarning,
match=(
"Logger 'tests.test_logging' attempted to send logs to the API without"
" a flow run id."
),
):
logger.info("test")
except TypeError:
pytest.fail(
"Raised TypeError when logging outside of context with default `warn` setting."
)
except UserWarning:
pass
except Exception:
pytest.fail(
"Raised unexpected exception when logging outside of context with default `warn` setting."
)

def test_does_not_send_logs_outside_of_run_context_with_error_setting(
self, logger, mock_log_worker, capsys
Expand All @@ -548,20 +544,16 @@ def test_does_not_warn_when_logger_outside_of_run_context_with_error_setting(
logger,
):
with temporary_settings(
updates={PREFECT_LOGGING_ORION_WHEN_MISSING_FLOW: "error"},
updates={PREFECT_LOGGING_TO_API_WHEN_MISSING_FLOW: "error"},
):
try:
with pytest.raises(
MissingContextError,
match=(
"Logger 'tests.test_logging' attempted to send logs to the API"
" without a flow run id."
),
):
logger.info("test")
except UserWarning:
pytest.fail(
"Raised UserWarning when logging outside of context with `error` setting."
)
except MissingContextError:
pass
except Exception:
pytest.fail(
"Raised unexpected exception when logging outside of context with `error` setting."
)

def test_does_not_send_logs_outside_of_run_context_with_ignore_setting(
self, logger, mock_log_worker, capsys
Expand All @@ -582,22 +574,9 @@ def test_does_not_raise_or_warn_when_logger_outside_of_run_context_with_ignore_s
logger,
):
with temporary_settings(
updates={PREFECT_LOGGING_ORION_WHEN_MISSING_FLOW: "ignore"},
updates={PREFECT_LOGGING_TO_API_WHEN_MISSING_FLOW: "ignore"},
):
try:
logger.info("test")
except TypeError:
pytest.fail(
"Raised TypeError when logging outside of context with `ignore` setting."
)
except UserWarning:
pytest.fail(
"Raised UserWarning when logging outside of context with `ignore` setting."
)
except Exception:
pytest.fail(
"Raised unexpected exception when logging outside of context with `ignore` setting."
)
logger.info("test")

def test_does_not_send_logs_outside_of_run_context_with_warn_setting(
self, logger, mock_log_worker, capsys
Expand All @@ -622,20 +601,16 @@ def test_does_not_raise_when_logger_outside_of_run_context_with_warn_setting(
logger,
):
with temporary_settings(
updates={PREFECT_LOGGING_ORION_WHEN_MISSING_FLOW: "warn"},
updates={PREFECT_LOGGING_TO_API_WHEN_MISSING_FLOW: "warn"},
):
try:
with pytest.raises(
UserWarning,
match=(
"Logger 'tests.test_logging' attempted to send logs to the API"
" without a flow run id."
),
):
logger.info("test")
except TypeError:
pytest.fail(
"Raised TypeError when logging outside of context with `warn` setting."
)
except UserWarning:
pass
except Exception:
pytest.fail(
"Raised unexpected exception when logging outside of context with `warn` setting."
)

def test_missing_context_warning_refers_to_caller_lineno(
self, logger, mock_log_worker
Expand Down

0 comments on commit ea2d871

Please sign in to comment.