Skip to content

Any way to access the current iteration count? #52

Open

Description

@acohen716

If I'd like to use/display the current iteration count, is there any way to do that from within the Python test code?

Activity

  1. acohen716 commented on Aug 16, 2021

    @acohen716
    Author

    I've found this but it doesn't seem like the correct approach to handling this...

  2. joeyshelton commented on Mar 2, 2022

    @joeyshelton

    I came here wondering the same thing. This would be a small feature addition and it would be very helpful. Although, the creators of pytest-repeat may want to avoid the ability for a test's behavior to be dependent on iteration number.

  3. acohen716 commented on Mar 9, 2022

    @acohen716
    Author

    I personally decided to use the same logic as in the stackoverflow post in our conftest.py in order to log the current test and iteration as follows:

    import logging
    import pytest
    
    log = logging.getLogger(__name__)
    
    @pytest.fixture(scope="function", autouse=True)
    def log_test_function_start(request):
        """Logs test name at start of test, helps identify currently running test and iteration"""
        log.info("#################################################################")
        log.info("Starting execution of test: %s", request.node.name)
        log.info("##################################################################")
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions