From 3cf0a1642eafe53e3c3b40b06cf105a32676a27f Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Mon, 11 Nov 2019 14:57:08 -0500 Subject: [PATCH] Test fixture improvements - ensure we escape out percent signs when a CompiledSQL or RegexSQL has percent signs in the SQL or in the parameter repr - to support combinations, print out complete test name in skip messages, py.test environment gives us a way to do this Change-Id: Ia9e62f7c1026c1465986144c5757e35fc164a2b8 --- lib/sqlalchemy/testing/assertsql.py | 15 +++++++++++---- lib/sqlalchemy/testing/config.py | 4 ++++ lib/sqlalchemy/testing/exclusions.py | 5 ++++- lib/sqlalchemy/testing/plugin/plugin_base.py | 3 +++ lib/sqlalchemy/testing/plugin/pytestplugin.py | 3 +++ 5 files changed, 25 insertions(+), 5 deletions(-) diff --git a/lib/sqlalchemy/testing/assertsql.py b/lib/sqlalchemy/testing/assertsql.py index 6a654df1ec..3a8f459185 100644 --- a/lib/sqlalchemy/testing/assertsql.py +++ b/lib/sqlalchemy/testing/assertsql.py @@ -182,10 +182,13 @@ class CompiledSQL(SQLMatchRule): def _failure_message(self, expected_params): return ( - "Testing for compiled statement %r partial params %r, " + "Testing for compiled statement %r partial params %s, " "received %%(received_statement)r with params " "%%(received_parameters)r" - % (self.statement.replace("%", "%%"), expected_params) + % ( + self.statement.replace("%", "%%"), + repr(expected_params).replace("%", "%%"), + ) ) @@ -199,9 +202,13 @@ class RegexSQL(CompiledSQL): def _failure_message(self, expected_params): return ( - "Testing for compiled statement ~%r partial params %r, " + "Testing for compiled statement ~%r partial params %s, " "received %%(received_statement)r with params " - "%%(received_parameters)r" % (self.orig_regex, expected_params) + "%%(received_parameters)r" + % ( + self.orig_regex.replace("%", "%%"), + repr(expected_params).replace("%", "%%"), + ) ) def _compare_sql(self, execute_observed, received_statement): diff --git a/lib/sqlalchemy/testing/config.py b/lib/sqlalchemy/testing/config.py index 8262142ec5..ae84a7878c 100644 --- a/lib/sqlalchemy/testing/config.py +++ b/lib/sqlalchemy/testing/config.py @@ -89,6 +89,10 @@ def fixture(*arg, **kw): return _fixture_functions.fixture(*arg, **kw) +def get_current_test_name(): + return _fixture_functions.get_current_test_name() + + class Config(object): def __init__(self, db, db_opts, options, file_config): self._set_name(db) diff --git a/lib/sqlalchemy/testing/exclusions.py b/lib/sqlalchemy/testing/exclusions.py index 86f3b7aacd..97cee7e277 100644 --- a/lib/sqlalchemy/testing/exclusions.py +++ b/lib/sqlalchemy/testing/exclusions.py @@ -141,7 +141,10 @@ class compound(object): for skip in self.skips: if self._check_combinations(combination, skip) and skip(cfg): - msg = "'%s' : %s" % (fn.__name__, skip._as_string(cfg)) + msg = "'%s' : %s" % ( + config.get_current_test_name(), + skip._as_string(cfg), + ) config.skip_test(msg) try: diff --git a/lib/sqlalchemy/testing/plugin/plugin_base.py b/lib/sqlalchemy/testing/plugin/plugin_base.py index be1984c9e0..33967ec156 100644 --- a/lib/sqlalchemy/testing/plugin/plugin_base.py +++ b/lib/sqlalchemy/testing/plugin/plugin_base.py @@ -730,6 +730,9 @@ class FixtureFunctions(ABC): def fixture(self, *arg, **kw): raise NotImplementedError() + def get_current_test_name(self): + raise NotImplementedError() + _fixture_fn_class = None diff --git a/lib/sqlalchemy/testing/plugin/pytestplugin.py b/lib/sqlalchemy/testing/plugin/pytestplugin.py index 2f7df97fa6..44fccf28df 100644 --- a/lib/sqlalchemy/testing/plugin/pytestplugin.py +++ b/lib/sqlalchemy/testing/plugin/pytestplugin.py @@ -412,3 +412,6 @@ class PytestFixtureFunctions(plugin_base.FixtureFunctions): def fixture(self, *arg, **kw): return pytest.fixture(*arg, **kw) + + def get_current_test_name(self): + return os.environ.get("PYTEST_CURRENT_TEST") -- 2.47.2