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

Skip a scenario entirely based on @BeforeScenario #1437

Open
jnicola opened this issue Aug 18, 2023 · 4 comments
Open

Skip a scenario entirely based on @BeforeScenario #1437

jnicola opened this issue Aug 18, 2023 · 4 comments

Comments

@jnicola
Copy link

jnicola commented Aug 18, 2023

I'd like to be able to skip a scenario entirely based on some conditional checks in a @BeforeScenario.

For some of our test environments, we don't fully import the default content since it would bog down testing.

However, I want to be able to setup nightly test runs that do have the default content brought in.

Tests marked with a tag such as requiresInitialImport would check against the database to see if an import has been performed. If it hasn't, skip the test it's okay. If it has however had imports performed, it's fair game!

@jnicola
Copy link
Author

jnicola commented Aug 18, 2023

...also I know I can just have different environments / jenkins jobs exclude certain tags etc etc. I'm really not looking to solve this with tag exclusion, if possible.

@barryswaisland-eagleeye
Copy link

barryswaisland-eagleeye commented Oct 2, 2023

Just add this to a context...

    /**
     * @BeforeScenario
     */
    public function beforeScenario(BeforeScenarioScope $scope)
    {
        $tags = array_merge($scope->getScenario()->getTags(), $scope->getFeature()->getTags());
        if (in_array('requiresInitialImport', $tags, true) && !$this->databaseIsImported()) {
            throw new PendingException('required initial import'); 
        }
    }

@usu
Copy link

usu commented Dec 23, 2023

Just add this to a context...

    /**
     * @BeforeScenario
     */
    public function beforeScenario(BeforeScenarioScope $scope)
    {
        $tags = array_merge($scope->getScenario()->getTags(), $scope->getFeature()->getTags());
        if (in_array('requiresInitialImport', $tags, true) && !$this->databaseIsImported()) {
            throw new PendingException('required initial import'); 
        }
    }

Thanks. This worked for me when developing locally, however not for CI: Reason is that exit code is set to 1 (failed), whenever an exception is thrown during setup hooks.

Anyone has an idea on how to tweak exit code?

@barryswaisland-eagleeye

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants