Skip to content

Commit

Permalink
test: added skip_linux fixture as its needed for set_get_sockname
Browse files Browse the repository at this point in the history
since it requires Linux 6.7+ to work properly
  • Loading branch information
YoSTEALTH committed Jul 13, 2024
1 parent e8a85d2 commit 21f59a9
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
38 changes: 37 additions & 1 deletion test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import pathlib
import getpass
import tempfile
# import liburing
import liburing
# import shakti


Expand Down Expand Up @@ -32,3 +32,39 @@ def tmp_dir():
if not os.path.exists(path):
os.mkdir(path)
return pathlib.Path(tempfile.mkdtemp(dir=path))


# linux version start >>>
LINUX_VERSION = f'{liburing.LINUX_VERSION_MAJOR}.{liburing.LINUX_VERSION_MINOR}'


@pytest.fixture(autouse=True)
def skip_by_platform(request):
'''
Example
>>> @pytest.mark.skip_linux(6.7)
>>> def test_function():
...
test.py::test_function SKIPPED (Linux `6.7 < 6.8`)
>>> @pytest.mark.skip_linux(6.7, 'custom message')
>>> def test_function():
...
test.py::test_function SKIPPED (custom message)
>>> @pytest.mark.skip_linux('6.7', '')
>>> def test_function():
...
test.py::test_function SKIPPED
'''
if r := request.node.get_closest_marker('skip_linux'):
if liburing.linux_version_check(version := r.args[0]):
msg = r.args[1] if len(r.args) > 1 else f'Kernel `{LINUX_VERSION} < {version}`'
pytest.skip(msg)


def pytest_configure(config):
config.addinivalue_line(
"markers",
"skip_linux(version:str|float|int, message:str): skipping linux version not supported.")
# linux version end <<<
3 changes: 2 additions & 1 deletion test/io/socket_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def test_socket():
socket(),
bind(),
listen(),
# set_get_sockname(), # TODO: buggy
set_get_sockname(),
echo_client(random_port),
echo_server(random_port),
)
Expand Down Expand Up @@ -56,6 +56,7 @@ async def listen():
await shakti.close(sockfd)


@pytest.mark.skip_linux('6.7')
async def set_get_sockname():
assert (socket_fd := await shakti.socket()) > 0
try:
Expand Down

0 comments on commit 21f59a9

Please sign in to comment.