Skipping collection test but in the results it shows as skipped and failed

tests
collections
#1

I have a test set in a collection to check whether the status of the response is one of a list:

pm.test('Check status code', () => {
    pm.expect(pm.response.code).to.be.oneOf([200, 201, 202, 203, 204, 205, 206, 207, 208, 226])
})

In the Pre-request script of two of my requests, I have a line to skip the test that is set up for this collection (as I know the response of these two particular tests is going to be different but that’s ok for these as individual requests).

pm.test.skip(‘Check status code’)

However, when I run the collection, the results show that the relevant tests have been skipped AND failed. How is this happening?

*Note - if I have the full skip instruction as this, it still skips and fails:

pm.test.skip('Check status code', () => {
    pm.expect(pm.response.code).to.be.oneOf([200, 201, 202, 203, 204, 205, 206, 207, 208, 226])
})

Thank you in advance!

#2

Hey @daniel.goddard,

Welcome to the community :wave:

Unfortunately, The skipped tests don’t really work in this way pm.test.skip(‘Check status code’) but it’s a good idea for a new feature - To have it work in a similar way as the postman.setNextRequest() workflow. :slight_smile:

This code and process have been copied from @vdespa - He created an awesome video explaining how this would work.

For this, I’ve kept the same naming convention but you could choose something that matches your context.

By using this code at the collection level, the test will be skipped if the environment variable matches - If it doesn’t, the test will run.

const isLocal = pm.environment.get('environment') === 'local';

(isLocal ? pm.test.skip : pm.test)("Check status code", () => {
    pm.expect(pm.response.code).to.be.oneOf([200, 201, 202, 203, 204, 205, 206, 207, 208, 226])
});

By adding the local value to the environment key, your tests will be skipped:

Without the variable set, it will run the test:

This is just a simple solution to the problem and I’m sure that there are other methods out there to achieve the same thing. :slight_smile:

#3

Thanks @dannydainton.

Unfortunately, I only need to skip my test for 2 out of 40 requests in the same environment and collection - is it possible to alter the skip code to skip two specific tests?

Basically, the two tests I need to skip may return a 429 code, which is fine for those two tests but not the other 38, so I don’t want to set the test at collection level to say “accept a 429 for all requests” - if that makes sense.

#4

I don’t know a great deal about the context you work in and the reason for those checks, I can only offer a couple of different approaches that may or may not work :slight_smile:

If you know which checks cause that 429 status code, you could separate them out to different folders? Bring the tests down a level rather than having them all at the collection level? That might add another level of control.

Or maybe changing the test to look for the 429 status code and skipping it that way but then you run the risk of skipping ones that you thought where going to part of the 2XX range.

if (pm.response.code === 429) {
    pm.test.skip("Too many requests", () => {
        pm.response.to.be.rateLimited
    });
}
else {
    pm.test(`Status code was ${pm.response.code}`, () => {
        pm.response.to.be.success
    });
}

There are lots of different things to consider but it’s tough to give a better honest without being in your context.

1 Like
#5

That’s a great help, thanks. I’d not considered separating the requests out into folders. I’d thought about looking for the 429 and ignoring it but not quite got my head round writing the test for it. Thanks again!

#6

No worries. Always happy to help. :trophy:

Another, simpler way (credit to @sivcan for this :slight_smile: ) of looking for the status code and skipping the tests would be this:

    let skipTest = pm.response.code === 429;

    // Add this to the beginning of all the tests that need to be skipped when the status code is 429 
    // -> (skipTest ? pm.test.skip : pm.test)
    //
    // For eg:
    (skipTest ? pm.test.skip : pm.test)("Check status code", () => {
        pm.response.to.be.success
    });

This is just using a local variable to check if the response returns a 429 status code and is not using an environment variable, like a mentioned in the first reply. :slight_smile:

2 Likes
#7

This is perfect, cheers :slight_smile: