Skip to content

How to parameterize the entire test suite? #3196

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

Closed
Drew-Ack opened this issue Feb 9, 2018 · 9 comments
Closed

How to parameterize the entire test suite? #3196

Drew-Ack opened this issue Feb 9, 2018 · 9 comments
Labels
type: question general question, might be closed after 2 weeks of inactivity

Comments

@Drew-Ack
Copy link

Drew-Ack commented Feb 9, 2018

I want to be able to have pytest run the test suite in firefox, then chrome, then IE. All in one swoop.

I know its possible to parameterize test functions, but i'm not sure if this is possible to do on a test suite level.

Is this possible to do in pytests scope?

@nicoddemus
Copy link
Member

nicoddemus commented Feb 9, 2018

I want to be able to have pytest run the test suite in firefox, then chrome, then IE. All in one swoop.

Usually this is done by parametrizing a fixture which is used by some/all your tests, for example:

@pytest.fixture(params=['firefox', 'chrome', 'IE']
def browser(request):
    return request.param

Now every test which requests browser will be executed multiple times, once for each parameter.

@nicoddemus nicoddemus added the type: question general question, might be closed after 2 weeks of inactivity label Feb 9, 2018
@Drew-Ack
Copy link
Author

Drew-Ack commented Feb 9, 2018

Wouldnt this cause a staggered behaviour though?

Test A - Firefox
Test A - Chrome
Test A - IE

Instead of what i want which is
Test A - FireFox
Test B - Firefox
Test C - Firefox

Test A - Chrome...
and so on.

@nicoddemus
Copy link
Member

pytest will automatically reorder session-scoped fixtures to avoid creating/destroying them too much, so it will execute in the order you want. 😁

@nicoddemus
Copy link
Member

I'm closing this for now @Drew-Ack, but feel free to post further question.

@sjpotter
Copy link

is it possible to make it work with dependencies, where you depend on the depency called with the same fixture value.

currently we depend on function name, but that breaks, as the fixture value becomes part of the signature.

@The-Compiler
Copy link
Member

@sjpotter Using the same fixture multiple times during a test will give you the same (cached) value. I don't really follow though, do you have an example?

@sjpotter
Copy link

something like this (though this isn't quite)

@pytest.fixture(scope="session", params=[False, True])
def tags(request):
    return request.param


class TestTestyMcTester
    @pytest.mark.dependency()
    def test_create_database(self, tags):
         ....

     @pytest.mark.dependency(depends=["TestTestyMcTester::test_create_database"])
     def test_database_services(self, tags):
     ....

perhaps not the best way to do it, but until I removed the depends lines, it is skipping all those tests as they don't match (I think) because the fixture changes the signature.

when I remove them, the tests run as I expect (i.e. test_create_database(False) -> test_database_service(Fales) -> test_create_database(True) -> test_database_service(True), but would prefer that dependency handling was still there (i.e. all my test functions with proper dependencies)

@The-Compiler
Copy link
Member

I guess whatever pytest.mark.dependency is depends on the so-called "node id", which indeed changes when parametrized. That's something which would need to be changed in whatever project implements @pytest.mark.dependency, though.

@sjpotter
Copy link

ah, ok, I thought it was part of core pytest, apparently it isn't, hence when figuring out how to do it, found this. will investigate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: question general question, might be closed after 2 weeks of inactivity
Projects
None yet
Development

No branches or pull requests

4 participants