From: Mike Bayer Date: Mon, 11 Nov 2019 19:57:08 +0000 (-0500) Subject: Test fixture improvements X-Git-Tag: rel_1_3_11~2^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=889aacd277f5f293f6dd999e375163bb6f5463bc;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git 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 (cherry picked from commit 3cf0a1642eafe53e3c3b40b06cf105a32676a27f) --- diff --git a/lib/sqlalchemy/testing/assertsql.py b/lib/sqlalchemy/testing/assertsql.py index 00496d5490..63f7811d0b 100644 --- a/lib/sqlalchemy/testing/assertsql.py +++ b/lib/sqlalchemy/testing/assertsql.py @@ -183,10 +183,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("%", "%%"), + ) ) @@ -200,9 +203,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 cf61091e3f..f742064402 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 c5323921af..8afe69d354 100644 --- a/lib/sqlalchemy/testing/plugin/plugin_base.py +++ b/lib/sqlalchemy/testing/plugin/plugin_base.py @@ -722,6 +722,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 5cb6d1b4cd..dc83f1f51a 100644 --- a/lib/sqlalchemy/testing/plugin/pytestplugin.py +++ b/lib/sqlalchemy/testing/plugin/pytestplugin.py @@ -414,3 +414,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")