diff --git a/conftest.py b/conftest.py index 8fba8c85550..b10e0e62705 100644 --- a/conftest.py +++ b/conftest.py @@ -109,7 +109,12 @@ def pytest_collection_modifyitems(config, items): @pytest.fixture(autouse=True) -def reset_conf_before_test(): +def reset_conf_before_test(request): + # To prevent running this fixture for a specific test, you need to use this + # marker. + if 'no_reset_conf' in request.keywords: + return + from spyder.config.manager import CONF CONF.reset_to_defaults(notification=False) diff --git a/spyder/config/tests/test_user.py b/spyder/config/tests/test_user.py index 8eeade67c77..4a21ded64b1 100644 --- a/spyder/config/tests/test_user.py +++ b/spyder/config/tests/test_user.py @@ -377,6 +377,30 @@ def test_userconfig_cleanup(userconfig): assert not os.path.isfile(configpath) +@pytest.mark.no_reset_conf +def test_invalid_shortcuts(tmp_path): + name = 'invalid-shortcuts' + path = str(tmp_path) + + for defaults in [ + # Shortcut is not of the form context/name + [('shortcuts', {'foo': "Ctrl+I"})], + # Shortcut contains more than one slash, which breaks the way we parse + # them + [('shortcuts', {'editor/foo/bar': "Ctrl+I"})], + ]: + with pytest.raises(ValueError): + UserConfig( + name=name, + path=path, + defaults=defaults, + load=False, + version="1.0.0", + backup=False, + raw_mode=True, + ) + + # --- SpyderUserConfig tests # ============================================================================ # --- Compatibility API