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

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!

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:

1 Like

Thanks @danny-dainton.

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.

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.

2 Likes

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!

No worries. Always happy to help. :trophy:

Another, simpler way (credit to @singhsivcan 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:

3 Likes

This is perfect, cheers :slight_smile: