Skip to content

Incremental testing from example in documentation #3125

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
kam1sh opened this issue Jan 17, 2018 · 10 comments
Closed

Incremental testing from example in documentation #3125

kam1sh opened this issue Jan 17, 2018 · 10 comments
Labels
type: docs documentation improvement, missing or needing clarification

Comments

@kam1sh
Copy link

kam1sh commented Jan 17, 2018

At first, thank you for pytest. This is great framework for testing with good interface and reporting.
I wanted to separate my test case into steps, for example:

class TestCreateUser(object):
    def test_create_user(self, webdriver):
        assert True
    def test_user_login(self, webdriver):
        assert False
    def test_user_logout(self, webdriver):
        assert True
    def test_delete_user(self, webdriver):
        assert True

I did it just because it looks nice in report. You know, if one part of scenario fails, you could see which part failed, with no need to read tracebacks.
So, I used code from documentation, and now if one step fails, the next methods will not be executed.
But today I discovered, if methods use parameters or fixture with parameters, weird things starts happening:

test_create_user.py::TestCreateUser::test_create_user[chrome] PASSED test_create_user.py::TestCreateUser::test_user_login[chrome] FAILED test_create_user.py::TestCreateUser::test_user_logout[chrome] xfail test_create_user.py::TestCreateUser::test_delete_user[chrome] xfail
%other tests% PASSED
test_create_user.py::TestCreateUser::test_create_user[firefox] xfail test_create_user.py::TestCreateUser::test_user_login[firefox] xfail test_create_user.py::TestCreateUser::test_user_logout[firefox] xfail test_create_user.py::TestCreateUser::test_delete_user[firefox] xfail

As you can see, if once class method has FAILED state, the next steps will be xfailed even with different param. This is the first bug with this code.
The second bug -- next steps also will be xfailed, if current test have been skipped with @pytest.mark.skip:

test_create_user.py::TestCreateUser::test_create_user[chrome] PASSED test_create_user.py::TestCreateUser::test_user_login[chrome] SKIPPED test_create_user.py::TestCreateUser::test_user_logout[chrome] xfail test_create_user.py::TestCreateUser::test_delete_user[chrome] xfail

I tried to fix first bug manually, but I don't know well pytest API. Eventually, I decided not to use incremental testing at all.
...but I'll be glad if you fix this code in future releases.
My testing environment is: Python 3.6.3, pytest-3.3.2, py-1.5.2, pluggy-0.6.0

@pytestbot
Copy link
Contributor

GitMate.io thinks the contributor most likely able to help you is @nicoddemus.

@pytestbot pytestbot added the type: bug problem that needs to be addressed label Jan 17, 2018
@nicoddemus
Copy link
Member

@kam1sh thanks for reporting this.

Indeed the sample is not handling parametrization and skipping. We should update the documentation with another example that handle these.

@nicoddemus nicoddemus added type: docs documentation improvement, missing or needing clarification and removed type: bug problem that needs to be addressed labels Jan 17, 2018
@smarie
Copy link
Contributor

smarie commented Oct 11, 2018

You may also wish to have a look at pytest-steps if you need a bit more control over the various dependencies inside the class (instead of just monotonic incremental). I am aware that this does not help fixing the pytest doc, but I am quite happy with the result so I'm just willing to share :)

@sdementen
Copy link
Contributor

I have found a discussion on stackoverflow on the issue and posted an answer https://stackoverflow.com/a/57854471/2352026 (that I am using in my tests suite). Maybe a potential solution ?

@kam1sh
Copy link
Author

kam1sh commented Sep 13, 2019

@sdementen right now I think the solution could be implement at pytest level some kind of UUID for each test, because remembering test by its full name+fixtures is complicated. But maybe I'm wrong, because I worked with this issue a long ago =/

@sdementen
Copy link
Contributor

@kam1sh I do not understand immediately how a UUID would be beneficial in this context. Could you elaborate?

@RonnyPfannschmidt
Copy link
Member

As far as I can tell it's not beneficial in any way

@blueyed
Copy link
Contributor

blueyed commented Jan 24, 2020

@sdementen
Copy link
Contributor

Ok @blueyed , I work on it when I find some spare time

@sdementen
Copy link
Contributor

@blueyed I have pushed a PR. Could you review and tell me if it is okay or need other changes:

  • tests ? I do not see it for the current incremental marker
  • changelog ? if worth...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: docs documentation improvement, missing or needing clarification
Projects
None yet
Development

No branches or pull requests

7 participants