Skip to content

Commit

Permalink
Merge pull request #279 from dwalters/pytest8-compat
Browse files Browse the repository at this point in the history
fix: support for pytest7+
  • Loading branch information
casperisfine authored May 24, 2024
2 parents dcc6fe4 + a7aaec1 commit 24a4059
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 9 deletions.
16 changes: 12 additions & 4 deletions python/ciqueue/_pytest/outcomes.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ class UnserializableException(Exception):
Failed: outcomes.Failed}


try:
from_exc_info = code.ExceptionInfo.from_exc_info
except AttributeError:
# pytest < 7.4
def from_exc_info(tup):
return code.ExceptionInfo(tup)


def swap_in_serializable(excinfo):
def pickles(excinfo):
try:
Expand All @@ -52,22 +60,22 @@ def pickles(excinfo):
if excinfo.type in SERIALIZE_TYPES:
cls = SERIALIZE_TYPES[excinfo.type]
tup = (cls, cls(*excinfo.value.args), excinfo.tb)
excinfo = code.ExceptionInfo(tup)
excinfo = from_exc_info(tup)
elif not pickles(excinfo):
tup = (UnserializableException,
UnserializableException(
"Actual Exception thrown on test node was %r" %
excinfo.value),
excinfo.tb)
excinfo = code.ExceptionInfo(tup)
excinfo = from_exc_info(tup)
return excinfo


def swap_back_original(excinfo):
if excinfo.type in DESERIALIZE_TYPES:
tipe = DESERIALIZE_TYPES[excinfo.type]
tup = (tipe, tipe(*excinfo.value.args), excinfo.tb)
return code.ExceptionInfo(tup)
return from_exc_info(tup)
return excinfo


Expand All @@ -84,4 +92,4 @@ def failed(item):
def skipped_excinfo(item, msg):
traceback = list(item.error_reports.values())[0]['excinfo'].tb
tup = (outcomes.Skipped, outcomes.Skipped(msg), traceback)
return code.ExceptionInfo(tup)
return from_exc_info(tup)
2 changes: 1 addition & 1 deletion python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def get_lua_scripts():
packages=['ciqueue', 'ciqueue._pytest'],
install_requires=[
'dill>=0.2.7',
'pytest>=2.7,<7',
'pytest>=2.7',
'redis>=2.10.5',
'tblib>=1.3.2',
'uritools>=2.0.0',
Expand Down
11 changes: 9 additions & 2 deletions python/tests/test_pytest.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
import os
import re
import subprocess
import redis
import pytest

# pylint: disable=no-self-use


@pytest.fixture(autouse=True)
def change_test_dir(request, monkeypatch):
monkeypatch.chdir(request.fspath.dirname + "/..")


def expected_messages(output):
assert '= 4 failed, 2 passed, 1 skipped, 1 xpassed, 6 errors in' in output, output
assert ('integrations/pytest/test_all.py:27: skipping test message' in output
or 'integrations/pytest/test_all.py:28: skipping test message' in output), output
assert re.search(r':\d+: skipping test message', output) is not None, \
"did not find 'skipping test message' in output"


def check_output(cmd):
Expand Down
4 changes: 2 additions & 2 deletions python/tests/test_test_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
class TestTestQueue:
def test_initialise_from_redis_uri(self):
queue = test_queue.build_queue('redis://localhost:6379/0?worker=1&build=12345', None)
assert type(queue) is ciqueue.distributed.Supervisor
assert isinstance(queue, ciqueue.distributed.Supervisor)
assert queue.redis is not None

def test_initialise_from_rediss_uri(self):
queue = test_queue.build_queue('rediss://localhost:6379/0?worker=1&build=12345', None)
assert type(queue) is ciqueue.distributed.Supervisor
assert isinstance(queue, ciqueue.distributed.Supervisor)
assert queue.redis is not None

0 comments on commit 24a4059

Please sign in to comment.