# Does postman know how it's test scripts are being executed?

**URL:** <https://community.postman.com/t/does-postman-know-how-its-test-scripts-are-being-executed/17921>\
**Category:** Help Hub\
**Created:** [November 20, 2020, 9:20pm UTC](https://community.postman.com/t/does-postman-know-how-its-test-scripts-are-being-executed/17921 "2020-11-20T21:20:54Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![robmcec](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/robmcec/32/5857_2.png) [@robmcec](https://community.postman.com/u/robmcec)\
**Post date:** [November 20, 2020, 9:20pm UTC](https://community.postman.com/t/does-postman-know-how-its-test-scripts-are-being-executed/17921/1 "2020-11-20T21:20:54Z")

</div>

For example, is there a way to only execute test script code if it’s being run by the runner and not by pressing send?

---

<div class="post-metadata">

**Author:** ![kevin.swiber](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/kevin.swiber/32/3820_2.png) [@kevin.swiber](https://community.postman.com/u/kevin.swiber)\
**Post date:** [November 20, 2020, 9:47pm UTC](https://community.postman.com/t/does-postman-know-how-its-test-scripts-are-being-executed/17921/2 "2020-11-20T21:47:35Z")

</div>

Hi @robmcec!

The `pm` API doesn’t have anything to check if it’s being executed as part of a collection run, but you can do this yourself.

1. Add a Request above the one that includes your tests. It can go to a dummy URL, like `https://postman-echo.com/get`. In the Tests tab, set a variable to indicate you’re in a collection run.

```auto
pm.variables.set('isCollectionRun', 'true');

```

1. Now, in the Tests tab of the Request for which you want to conditionally execute tests, add some logic around this variable.

```auto
const isCollectionRun = pm.variables.get('isCollectionRun') === 'true';

if (isCollectionRun) {
    pm.test('status code is 200', () => {
        pm.response.to.have.status(200);
    });
}

```

Now, when you run just the individual request, the test shouldn’t execute. When you run it as part of a collection run, the initializing request will execute first, setting the variable, the condition will past, and the test will run.

Hope this helps.

Best,

Kevin
