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

Allow marked tests to be skipped under Windows #44

Open
webknjaz opened this issue Jul 20, 2020 · 2 comments
Open

Allow marked tests to be skipped under Windows #44

webknjaz opened this issue Jul 20, 2020 · 2 comments

Comments

@webknjaz
Copy link
Member

Currently, if the test is marked with forked, this plugin tries to run it in a forked subprocess regardless of the current env. Also, adding a conditional skip marker does not help and manifests itself as pytest-dev/pytest#7327.

The following snippet still runs on Windows:

@pytest.mark.skipif(IS_WINDOWS, ...)
@pytest.mark.forked
def test():
    ...

The workaround that I currently use is:

@pytest.mark.skipif(IS_WINDOWS, ...)
def test():
    ...

if not IS_WINDOWS:
    test = pytest.mark.forked(test)

This could be addressed in a few ways:

  1. Actually respect skip markers.
  2. Skip any tests marked with forked when the env is not supported.
  3. Run these tests but w/o trying to sandbox them.

I think I like 1+2 most.

@moble
Copy link

moble commented Sep 11, 2020

For me, the easiest workaround is just to use a different decorator:

import sys
import pytest


if sys.platform == "win32":
    forked = pytest.mark.skip(reason="Windows doesn't fork")
else:
    forked = pytest.mark.forked

@forked
def test_thing_in_fork():
    ...

The first branch could also be forked = lambda f: f to fall back to non-forking, as in option 3 above.

@untitaker
Copy link
Contributor

untitaker commented Sep 24, 2020

You can write this, place it anywhere in conftest and use the marker like normal:

@pytest.fixture(autouse=True)
def skip_forked_tests_on_windows(request):
    if request.node.get_closest_marker("forked") and sys.platform == "win32":
        pytest.skip("Windows doesn't work")

EDIT: Ah the fixture is only executed in the forked process, that's a bummer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants