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

Fix/IVS-122 - No error handling for non-behave errors in production #322

Conversation

Ghesselink
Copy link
Contributor

No description provided.

@Ghesselink Ghesselink requested review from aothms and civilx64 November 4, 2024 19:09
Copy link
Contributor

@civilx64 civilx64 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One small change, otherwise looks good!

if not 'Behave errors' in context.step.error_message: #exclude behave output from exception logging
context.caught_exceptions.append(ExceptionSummary.from_context(context))
execution_mode = context.config.userdata.get('execution_mode')
if execution_mode and execution_mode == 'ExecutionMode.TESTING':
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if execution_mode and execution_mode == 'ExecutionMode.TESTING':
if execution_mode and execution_mode == ExecutionMode.TESTING:

ExecutionModel is an enumeration, not a string.

Copy link
Contributor Author

@Ghesselink Ghesselink Nov 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It originally is, but the behave context stack outputs it as a string.

context.config.userdata.get('execution_mode')
'ExecutionMode.TESTING'
type(context.config.userdata.get('execution_mode'))
<class 'str'>

What we can do is how we solved this earlier in the code, with using eval. That way, the variable is back to it's original enumeration data type.

eval(context.config.userdata.get('execution_mode'))
<ExecutionMode.TESTING: 0>
type(eval(context.config.userdata.get('execution_mode')))
<enum 'ExecutionMode'>
eval(context.config.userdata.get('execution_mode')) == ExecutionMode.TESTING
True

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also bumped into this from time to time. Just a general recommendation from my side not to use eval().

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just out of curiosity, why? A reason I can come up with is that it would perhaps be safer to pass data around with the os environment rather than the behave stack.

os.environ["EXECUTION_MODE"] = execution_mode.name

And retrieve it;

execution_mode = ExecutionMode[os.environ.get('EXECUTION_MODE')]
execution_mode == ExecutionMode.TESTING
True

@civilx64 civilx64 merged commit 5442530 into development Nov 12, 2024
2 checks passed
@civilx64 civilx64 deleted the IVS-112-No_Error_Handling_For_Non-Behave_Errors_in_Production branch November 12, 2024 02:36
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

Successfully merging this pull request may close these issues.

3 participants