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

Inverse markers #3700

Closed
kjeldflarup opened this issue Jul 20, 2018 · 12 comments
Closed

Inverse markers #3700

kjeldflarup opened this issue Jul 20, 2018 · 12 comments
Labels
type: enhancement new feature or API change, should be merged into features branch

Comments

@kjeldflarup
Copy link

There is a posibility to use markers
@pytest.mark.playstation

And then run pytest -m "not playstation"
That would run all my tests except the playstation tests. Now if I want a complete playstation test, I just type pytest.
That however gives me errors on xbox, Wii, gamebody, nintendods etc.

Thus a test must be executed in this cumbersome way
pytest -m "not xbox and not Wii and not gamebody and not nintendods"

Is there a smarter way to do this? The markers operates quite inverse of what I need.

I could of course use skip, but then I would get a zillion skip messages, where I only wanted to know the skip messages for the playstation.

A decorator like @pytest.ignoreif(... ) would be nice.

@pytestbot
Copy link
Contributor

GitMate.io thinks possibly related issues are #277 (Markers as functions), #1603 (Get marker list of an item), #631 (markers leaking), #568 (markers stains on all related classes), and #1415 (Ability to register markers from plugins).

@pytestbot pytestbot added platform: mac mac platform-specific problem type: enhancement new feature or API change, should be merged into features branch labels Jul 20, 2018
@robert-cody
Copy link

robert-cody commented Jul 21, 2018

pytest -m 'playstation'?

@kjeldflarup
Copy link
Author

pytest -m "playstation" does not run common tests for all platforms.

@robert-cody
Copy link

robert-cody commented Jul 21, 2018

That's what you need, right?

You need:

pytest -m 'not xbox and not Wii and not gamebody and not nintendods'

Smarter way for the same result:

pytest -m 'playstation'

This command will run "complete playstation test", but not others.

@kjeldflarup
Copy link
Author

No Your solution does not run test_common_login

@pytest.mark.playstation
def test_playstation():
    pass

def test_common_login():
    pass

@RonnyPfannschmidt
Copy link
Member

as far as i understood you are trying to use markers for environment selection - mark expressions are simply not designed for that, and shouldn't be

@robert-cody
Copy link

robert-cody commented Jul 21, 2018

You can apply mark 'common' for common tests and run it like this:
pytest -m 'common or playstation'

@kjeldflarup
Copy link
Author

@RonnyPfannschmidt is there any way to do environment selection then?

@RonnyPfannschmidt
Copy link
Member

@kjeldflarup i do have something about it in a work project, unfortunately it's not going to be extracted soon, but basically this needs to be experimented with in a plug-in since its easy to get the actual semantics wrong as long as there isn't more than one consumer

@obestwalter obestwalter removed the platform: mac mac platform-specific problem label Jul 21, 2018
@kjeldflarup
Copy link
Author

kjeldflarup commented Aug 1, 2018

I found a solution by making pytest_collection_modifyitems remove the tests.
In this way I could also control ex. a --nightly switch to extend the test.

def pytest_addoption(parser):
    group = parser.getgroup("DEIF")
    group.addoption(
        "--duttype",
        action="store",
        dest="name",
        default=None,
        help='When dut marked, only run this dut.',
    )

def pytest_collection_modifyitems(session,config,items):
    duttype = config.getoption("--duttype")
    keep, discard = [], []
    i = 0
    for item in items:
        duts = item.get_marker('dut')
        if duts:
            # search the dut marker, to see if duttype is marked
            # multiple dut markers allowed
            found = False
            for dut in duts:
                for dutargs in dut.args:
                    if dutargs == duttype:
                        found = True
            if found:
                keep.append(item)
            else:
                discard.append(item)
        else:
            # dut marker not set, always run the test
            keep.append(item)

    items[:] = keep
    # The deselected information is not interesting
    #config.hook.pytest_deselected(items=discard)

@esben
Copy link

esben commented Aug 6, 2018

See https://pytest.readthedocs.io/en/reorganize-docs/example/markers.html#marking-platform-specific-tests-with-pytest
which can simple be extended to work with a command-line specified (target) platform, if sys.platform does not suffice.

@Zac-HD
Copy link
Member

Zac-HD commented Nov 20, 2019

Closing this as a combination of inactive, has workarounds, and markers seeming like the wrong solution 😕

@Zac-HD Zac-HD closed this as completed Nov 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement new feature or API change, should be merged into features branch
Projects
None yet
Development

No branches or pull requests

7 participants