Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(testing): allow test to be run using pytest-xdist #2172

Merged
merged 2 commits into from
Oct 14, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}')
vytas7 marked this conversation as resolved.
Show resolved Hide resolved
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