Skip to content

Commit

Permalink
explicit register slow_test pytest mark to get rid of pytest warning
Browse files Browse the repository at this point in the history
  • Loading branch information
janusheide committed Feb 20, 2024
1 parent c989535 commit 359b12d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 26 deletions.
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ packages = ["multipart"]
[tool.hatch.build.targets.sdist]
include = ["/multipart", "/tests"]

[tool.pytest.ini_options]
markers = [
"slow_test: marks tests as slow (deselect with '-m \"not slow_test\"')",
]

[tool.ruff]
line-length = 120

Expand Down
23 changes: 0 additions & 23 deletions tests/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,29 +32,6 @@ def _samefile(x, y):
sys.path.insert(0, path)


# Check if pytest is imported. If so, we use it to create marking decorators.
# If not, we just create a function that does nothing.
try:
import pytest
except ImportError:
pytest = None

if pytest is not None:
slow_test = pytest.mark.slow_test
xfail = pytest.mark.xfail

else:

def slow_test(x):
return x

def xfail(*args, **kwargs):
if len(args) > 0 and isinstance(args[0], types.FunctionType):
return args[0]

return lambda x: x


# We don't use the pytest parametrizing function, since it seems to break
# with unittest.TestCase subclasses.
def parametrize(field_names, field_values):
Expand Down
7 changes: 4 additions & 3 deletions tests/test_multipart.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from unittest.mock import Mock

import yaml
from pytest import mark

from multipart.decoders import Base64Decoder, QuotedPrintableDecoder
from multipart.exceptions import DecodeError, FileError, FormParserError, MultipartParseError
Expand All @@ -27,7 +28,7 @@
parse_options_header,
)

from .compat import parametrize, parametrize_class, slow_test
from .compat import parametrize, parametrize_class

if TYPE_CHECKING:
from multipart.multipart import FileConfig
Expand Down Expand Up @@ -905,7 +906,7 @@ def test_feed_blocks(self):
# Assert that our field is here.
self.assert_field(b"field", b"0123456789ABCDEFGHIJ0123456789ABCDEFGHIJ")

@slow_test
@mark.slow_test
def test_request_body_fuzz(self):
"""
This test randomly fuzzes the request body to ensure that no strange
Expand Down Expand Up @@ -978,7 +979,7 @@ def test_request_body_fuzz(self):
print("Failures: %d" % (failures,))
print("Exceptions: %d" % (exceptions,))

@slow_test
@mark.slow_test
def test_request_body_fuzz_random_data(self):
"""
This test will fuzz the multipart parser with some number of iterations
Expand Down

0 comments on commit 359b12d

Please sign in to comment.