reportportal / agent-python-pytest

Framework integration with PyTest
Apache License 2.0
94 stars 103 forks source link

Skip creating launch if no tests collected #343

Closed ntkathole closed 1 year ago

ntkathole commented 1 year ago

Is your feature request related to a problem? Please describe. We have different automation repositories for each component having parallel and sequential tests. Some components have only parallel test, some have only sequential tests while some components have both parallel and sequential tests. Thus, we have CI steps as follow:

stage("Run ${component} Parallel Tests") {
    sh "pytest -m parallel -n 4 --reportportal"
}
stage("Run ${component} Sequential Tests") {
    sh "pytest -m (not parallel) --reportportal"
}

The problem here is that it create empty launches in report portal for some components having only parallel or only sequential tests.

Describe the solution you'd like Launch should not be created if there are no tests collected.

Describe alternatives you've considered Right now, we are collecting tests first to check if there are any tests to run.

stage("Run ${component} Parallel Tests") {
    collectionStatus = sh(
         script: (
              "pytest -m parallel --collect-only"
         ), returnStatus: true
    )
    if (collectionStatus != 5) {
         sh "pytest -m parallel -n 2 --reportportal"
    }
}
stage("Run ${component} Sequential Tests") {
    collectionStatus = sh(
         script: (
              "pytest -m (not parallel) --collect-only"
         ), returnStatus: true
    )
    if (collectionStatus != 5) {
         sh "pytest -m (not parallel) --reportportal"
    }
}

But problem with this approach is this adds additional time in each component execution for test collection, which we want to improve.

Another alternative considered was to use script to delete empty launches, which will run every hour, and it adds additional maintenance.

HardNorth commented 1 year ago

@ntkathole, Unfortunately I have to decline it. We have to create launch on pytest_sessionstart hook which happens before we get know how many tests we run. That's because pytest supports multi-processing through xdist plugin: we don't really know how many (if any) tests each child process is going to run, but we need a master launch for child processes.