Skip to content

Commit

Permalink
tests: allow test to be run using pytest-xdist
Browse files Browse the repository at this point in the history
  • Loading branch information
CaselIT committed Sep 9, 2023
1 parent 32207fe commit 41d8428
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
11 changes: 11 additions & 0 deletions tests/_util.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from contextlib import contextmanager
import os

import pytest

import falcon
import falcon.asgi
import falcon.testing
Expand Down Expand Up @@ -65,3 +67,12 @@ def disable_asgi_non_coroutine_wrapping():

if should_wrap:
os.environ['FALCON_ASGI_WRAP_NON_COROUTINES'] = 'Y'


def as_params(*values, prefix=None):
if not prefix:
prefix = ''
return [
pytest.param(*value, id=f'{prefix}_{i}' if prefix else f'{i}')
for i, value in enumerate(values, 1)
]
6 changes: 4 additions & 2 deletions tests/test_uri_converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import string
import uuid

from _util import as_params
import pytest

from falcon.routing import converters
Expand Down Expand Up @@ -150,7 +151,7 @@ def test_datetime_converter_default_format():

@pytest.mark.parametrize(
'value, expected',
[
as_params(
(_TEST_UUID_STR, _TEST_UUID),
(_TEST_UUID_STR.replace('-', '', 1), _TEST_UUID),
(_TEST_UUID_STR_SANS_HYPHENS, _TEST_UUID),
Expand All @@ -163,7 +164,8 @@ def test_datetime_converter_default_format():
(_TEST_UUID_STR[0], None),
(_TEST_UUID_STR[:-1] + 'g', None),
(_TEST_UUID_STR.replace('-', '_'), None),
],
prefix='uuid',
),
)
def test_uuid_converter(value, expected):
c = converters.UUIDConverter()
Expand Down
7 changes: 4 additions & 3 deletions tests/test_uri_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from falcon import testing
from falcon.routing.util import SuffixedMethodNotFoundError

from _util import create_app # NOQA
from _util import as_params, create_app # NOQA


_TEST_UUID = uuid.uuid4()
Expand Down Expand Up @@ -314,7 +314,7 @@ def test_datetime_converter(client, resource, uri_template, path, dt_expected):

@pytest.mark.parametrize(
'uri_template, path, expected',
[
as_params(
(
'/widgets/{widget_id:uuid}',
'/widgets/' + _TEST_UUID_STR,
Expand Down Expand Up @@ -354,7 +354,8 @@ def test_datetime_converter(client, resource, uri_template, path, dt_expected):
'/widgets/' + _TEST_UUID_STR_SANS_HYPHENS[:-1] + '/orders',
None,
),
],
prefix='uuid_converter',
),
)
def test_uuid_converter(client, resource, uri_template, path, expected):
client.app.add_route(uri_template, resource)
Expand Down

0 comments on commit 41d8428

Please sign in to comment.