From 2c42b77d7898e86c1b465e770fa08b808f6435c5 Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Sun, 10 Jan 2021 05:15:27 +0100 Subject: [PATCH] Added randomisation of tests run Fixed a test dealing with an unpredictable libpq behaviour --- psycopg3/setup.py | 1 + tests/pq/test_escaping.py | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/psycopg3/setup.py b/psycopg3/setup.py index 6e7da1b7c..2befb50bd 100644 --- a/psycopg3/setup.py +++ b/psycopg3/setup.py @@ -34,6 +34,7 @@ extras_require = { "test": [ "pytest >= 6, < 6.1", "pytest-asyncio >= 0.14.0, < 0.15", + "pytest-randomly >= 3.5, < 3.6", ], "dev": [ "black", diff --git a/tests/pq/test_escaping.py b/tests/pq/test_escaping.py index b55c5132e..d6ba9de0b 100644 --- a/tests/pq/test_escaping.py +++ b/tests/pq/test_escaping.py @@ -122,13 +122,17 @@ def test_escape_string_1char(pgconn, scs): (b"", b""), (b"hello", b"hello"), (b"foo'bar", b"foo''bar"), - (b"foo\\bar", b"foo\\\\bar"), + # This libpq function behaves unpredictably when not passed a conn + (b"foo\\bar", (b"foo\\\\bar", b"foo\\bar")), ], ) def test_escape_string_noconn(data, want): esc = pq.Escaping() out = esc.escape_string(data) - assert out == want + if isinstance(want, bytes): + assert out == want + else: + assert out in want def test_escape_string_badconn(pgconn): -- 2.47.2