# Abort from step initialization

**URL:** <https://forum.opentap.io/t/abort-from-step-initialization/1295>\
**Category:** Technical\
**Tags:** python\
**Created:** [November 3, 2023, 9:57pm UTC](https://forum.opentap.io/t/abort-from-step-initialization/1295 "2023-11-03T21:57:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tmunsell10](https://avatars.discourse-cdn.com/v4/letter/t/58f4c7/32.png) [@tmunsell10](https://forum.opentap.io/u/tmunsell10)\
**Post date:** [November 3, 2023, 9:57pm UTC](https://forum.opentap.io/t/abort-from-step-initialization/1295/1 "2023-11-03T21:57:21Z")

</div>

Is there a way to safely abort from a step’s initialization function (specifically in Python), and not add the step to the test plan?

I have tried calling :

```csharp
OpenTap.TapThread.Current.Abort()
OpenTap.TestPlanRun.MainThread.Abort()

```

and raising errors. All of these are able to stop the step from being added, but the editor crashes shortly after.

I can also simply return from the **init** function, but this results in the step being added still.

Thanks

---

<div class="post-metadata">

**Author:** ![rolf\_madsen](https://avatars.discourse-cdn.com/v4/letter/r/43a26b/32.png) [@rolf\_madsen](https://forum.opentap.io/u/rolf_madsen)\
**Post date:** [November 4, 2023, 6:53am UTC](https://forum.opentap.io/t/abort-from-step-initialization/1295/2 "2023-11-04T06:53:00Z")

</div>

Hi @tmunsell10,

This is a known bug: [Exception thrown in \_\_init\_\_ causes onrecoverable error · Issue #118 · opentap/OpenTap.Python · GitHub](https://github.com/opentap/OpenTap.Python/issues/118)

Maybe you could explain why you need to block the user from adding the test step?

---

<div class="post-metadata">

**Author:** ![tmunsell10](https://avatars.discourse-cdn.com/v4/letter/t/58f4c7/32.png) [@tmunsell10](https://forum.opentap.io/u/tmunsell10)\
**Post date:** [November 6, 2023, 5:16pm UTC](https://forum.opentap.io/t/abort-from-step-initialization/1295/3 "2023-11-06T17:16:09Z")

</div>

Hi @rolf_madsen , yes - I wanted to block the user from adding the test step when the appropriate resources are not found in the bench settings.

Specifically, I was originally trying to create a robust way for a number of test steps to always use the correct resources.

For example, if a user is trying to run a certain test, but forgot to change the bench settings profile before adding the step, I’d like to stop the step from being added. Otherwise, an error would be generated due to failure to set a resource (if there are none of the desired resource), or the test might run incorrectly due to multiple steps using different resources (if there are too many of the desired resource).

There are a number of other ways I could try to enforce correct bench settings, but I was wondering if there was a clean way of stopping the step from being added in the first place.

---

<div class="post-metadata">

**Author:** ![rolf\_madsen](https://avatars.discourse-cdn.com/v4/letter/r/43a26b/32.png) [@rolf\_madsen](https://forum.opentap.io/u/rolf_madsen)\
**Post date:** [November 7, 2023, 10:24am UTC](https://forum.opentap.io/t/abort-from-step-initialization/1295/4 "2023-11-07T10:24:18Z")

</div>

Hi @tmunsell10,

Instead of trying to block the user from creating the test step I suggest you use validation rules to notify the user that the test step has been configured incorrectly.

If you make these kinds of constraints too rigid it might have unintended consequences for example when trying to load the test plan or work together with other plugins.

In general, it is good to be a bit tolerant with the settings - the users might do things in a different order than what you expect. But as long as the end result is the same, it should not matter.
