From a3ed3e1c2bec7305df746fba24972432766607f4 Mon Sep 17 00:00:00 2001 From: Maria Grimaldi Date: Wed, 10 Apr 2024 21:53:03 -0400 Subject: [PATCH] refactor: run bad args for callable test for python3.8/3.11 --- openedx_events/event_bus/tests/test_loader.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/openedx_events/event_bus/tests/test_loader.py b/openedx_events/event_bus/tests/test_loader.py index 720f3d7c..fae2c9f8 100644 --- a/openedx_events/event_bus/tests/test_loader.py +++ b/openedx_events/event_bus/tests/test_loader.py @@ -3,6 +3,8 @@ """ import copy +import sys +import pytest import warnings from contextlib import contextmanager from unittest import TestCase @@ -83,8 +85,9 @@ def test_missing_attribute(self): ) assert loaded == {'def': 'ault'} + @pytest.mark.skipif(sys.version_info < (3, 8), reason="requires Python 3.8+") @override_settings(EB_LOAD_PATH='builtins.dict') - def test_bad_args_for_callable(self): + def test_bad_args_for_callable_python38(self): with assert_warnings([ "Failed to load from setting EB_LOAD_PATH: " "TypeError('type object argument after * must be an iterable, not int'); " @@ -96,6 +99,20 @@ def test_bad_args_for_callable(self): ) assert loaded == {'def': 'ault'} + @pytest.mark.skipif(sys.version_info < (3, 11), reason="requires Python 3.11+") + @override_settings(EB_LOAD_PATH='builtins.dict') + def test_bad_args_for_callable_python311(self): + with assert_warnings([ + "Failed to load from setting EB_LOAD_PATH: " + "TypeError('dict() argument after * must be an iterable, not int'); " + "component will be inactive" + ]): + loaded = _try_load( + setting_name="EB_LOAD_PATH", args=(1), kwargs={'2': 3}, + expected_class=dict, default={'def': 'ault'}, + ) + assert loaded == {'def': 'ault'} + class TestProducer(TestCase):