Skip to content
Snippets Groups Projects
Commit 0d29c078 authored by David Douard's avatar David Douard
Browse files

Fix tests when executed directly with pytest in a editable-mode installed package situation

There are still situations where the swh root namespace is not properly
handled when running tests from pytest in an editable-mode installed
package situation, so make the 2 concerned tests pass in both cases.

Also replace a few `assert data.items() <= {xxx: xxx}.items()' idioms by
easier to read and understand statements.
parent e561d3cd
No related branches found
No related tags found
1 merge request!380Replace usage of pkg_resources by importlib and other code cleanups
Pipeline #9008 passed
......@@ -155,14 +155,9 @@ def test_rpc_server_exception(flask_app_client):
assert res.status_code == 500
assert res.mimetype == "application/x-msgpack", res.data
data = msgpack.loads(res.data)
assert (
data.items()
>= {
"type": "ValueError",
"module": "builtins",
"args": ["this is an unexpected exception"],
}.items()
), data
assert data["type"] == "ValueError"
assert data["module"] == "builtins"
assert data["args"] == ["this is an unexpected exception"]
def test_rpc_server_custom_exception(flask_app_client):
......@@ -178,14 +173,12 @@ def test_rpc_server_custom_exception(flask_app_client):
assert res.status_code == 503
assert res.mimetype == "application/x-msgpack", res.data
data = msgpack.loads(res.data)
assert (
data.items()
>= {
"type": "MyCustomException",
"module": "swh.core.api.tests.test_rpc_server",
"args": ["try again later!"],
}.items()
), data
assert data["type"] == "MyCustomException"
assert data["module"] in (
"swh.core.api.tests.test_rpc_server",
"core.api.tests.test_rpc_server",
)
assert data["args"] == ["try again later!"]
def test_rpc_server_psycopg2_adminshutdown(flask_app_client):
......@@ -203,14 +196,9 @@ def test_rpc_server_psycopg2_adminshutdown(flask_app_client):
assert res.status_code == 503
assert res.mimetype == "application/x-msgpack", res.data
data = msgpack.loads(res.data)
assert (
data.items()
>= {
"type": "AdminShutdown",
"module": "psycopg2.errors",
"args": ["cluster is shutting down"],
}.items()
), data
assert data["type"] == "AdminShutdown"
assert data["module"] == "psycopg2.errors"
assert data["args"] == ["cluster is shutting down"]
def test_rpc_server_psycopg2_querycancelled(flask_app_client):
......@@ -228,14 +216,9 @@ def test_rpc_server_psycopg2_querycancelled(flask_app_client):
assert res.status_code == 500
assert res.mimetype == "application/x-msgpack", res.data
data = msgpack.loads(res.data)
assert (
data.items()
>= {
"type": "QueryCanceled",
"module": "psycopg2.errors",
"args": ["too big!"],
}.items()
), data
assert data["type"] == "QueryCanceled"
assert data["module"] == "psycopg2.errors"
assert data["args"] == ["too big!"]
def test_rpc_server_extra_serializers(flask_app_client):
......
......@@ -251,7 +251,7 @@ def test_timed_no_metric(statsd):
name, value = name_value.split(":")
assert type_ == "ms"
assert name == "swh.core.tests.test_statsd.func"
assert name in ("swh.core.tests.test_statsd.func", "core.tests.test_statsd.func")
assert_almost_equal(500, float(value), 100)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment