Skip to content

Commit

Permalink
fix: skip & skipif usage
Browse files Browse the repository at this point in the history
Fixes #25
  • Loading branch information
willemt committed Jul 11, 2022
1 parent d4bee0c commit f57c385
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 12 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "pytest-asyncio-cooperative"
version = "0.27.0"
version = "0.28.0"
description = "Run all your asynchronous tests cooperatively."
authors = ["Willem Thiart <[email protected]>"]
license = "MIT"
Expand Down
11 changes: 6 additions & 5 deletions pytest_asyncio_cooperative/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import pytest

from _pytest.runner import call_and_report
from _pytest.skipping import Skip, evaluate_skip_marks

from .assertion import activate_assert_rewrite
from .fixtures import fill_fixtures
Expand Down Expand Up @@ -196,11 +197,11 @@ def pytest_runtestloop(session):
for item in session.items:
markers = {m.name: m for m in item.own_markers}

if "skip" in markers:
continue

if "skipif" in markers and markers["skipif"].args[0]:
continue
if "skip" in markers or "skipif" in markers:
# Best to hand off to the core pytest logic to handle this so reporting works
if isinstance(evaluate_skip_marks(item), Skip):
regular_items.append(item)
continue

# Coerce into a task
if "asyncio_cooperative" in markers:
Expand Down
64 changes: 58 additions & 6 deletions tests/test_skip.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
def test_skip(testdir):
def test_skipx(testdir):
testdir.makeconftest("""""")

testdir.makepyfile(
Expand All @@ -10,16 +10,16 @@ def test_skip(testdir):
@pytest.mark.skip(reason="for test")
@pytest.mark.asyncio_cooperative
async def test_a():
await asyncio.sleep(2)
raise Exception("should not be run!")
"""
)

result = testdir.runpytest()
# FIXME: should be skipped=1
result.assert_outcomes(errors=0, failed=0, passed=0, xfailed=0, xpassed=0, skipped=0)
result.assert_outcomes(errors=0, failed=0, passed=0, xfailed=0, xpassed=0, skipped=1)


def test_skipif(testdir):
def test_skipif_is_true(testdir):
testdir.makeconftest("""""")

testdir.makepyfile(
Expand All @@ -29,12 +29,64 @@ def test_skipif(testdir):
import pytest
@pytest.mark.skipif(sys.version_info < (9, 0), reason="too old")
@pytest.mark.skipif(sys.version_info < (99999999, 0), reason="too old")
@pytest.mark.asyncio_cooperative
async def test_a():
await asyncio.sleep(2)
raise Exception("should not be run!")
"""
)

result = testdir.runpytest()
result.assert_outcomes(errors=0, failed=0, passed=0, xfailed=0, xpassed=0, skipped=1)


def test_skipif_is_false(testdir):
testdir.makeconftest("""""")

testdir.makepyfile(
"""
import asyncio
import sys
import pytest
@pytest.mark.skipif(sys.version_info < (0, 0), reason="too old")
@pytest.mark.asyncio_cooperative
async def test_a():
await asyncio.sleep(0.1)
"""
)

result = testdir.runpytest()
result.assert_outcomes(errors=0, failed=0, passed=1, xfailed=0, xpassed=0, skipped=0)


def test_skipif_with_passing(testdir):
testdir.makeconftest("""""")

testdir.makepyfile(
"""
import pytest
SKIPPING = True
@pytest.mark.asyncio_cooperative
@pytest.mark.skip(reason="because reasons")
async def test_1():
assert True
@pytest.mark.asyncio_cooperative
@pytest.mark.skipif(SKIPPING, reason="because we need to skip")
async def test_2():
assert False
@pytest.mark.asyncio_cooperative
async def test_3():
assert True
"""
)

result = testdir.runpytest()
result.assert_outcomes(errors=0, failed=0, passed=1, xfailed=0, xpassed=0, skipped=2)

0 comments on commit f57c385

Please sign in to comment.