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

Add type attribute to TestSuite and TestCase objects #5287

Closed
pekkaklarck opened this issue Dec 9, 2024 · 2 comments
Closed

Add type attribute to TestSuite and TestCase objects #5287

pekkaklarck opened this issue Dec 9, 2024 · 2 comments

Comments

@pekkaklarck
Copy link
Member

pekkaklarck commented Dec 9, 2024

This attribute makes it easier to detect is a certain model object a suite, a test, a keyword or a control structure. One use case is implementing start_keyword in a visitor or a listener and wanting to know the type of kw.parent. A concrete use case is that JsonLogger implemented as part of #3423 needs to know is a parent of a teardown keyword a suite or a test.

Keywords and control structures already have a type attribute that's need also in JSON serialization, but using kw.parent.type currently fails if the parent happens to be a test or a suite. A workaround is importing appropriate classes and using something like isinstance(kw.parent, TestSuite), but in many usages using kw.parent == 'SUITE is more convenient. Another workaround is implementing also start_suite, start_test and start_body_item and keeping track of the parent type separately. That can be needed in some cases anyway, but in simple usages accessing the type attribute is a lot simpler.

@pekkaklarck
Copy link
Member Author

I believe good values for the type attribute are SUITE and TEST. Types used with keywords and control structures are defined as constants in the BodyItem class that is their common base class. I believe we should move constants to ModelObject that also TestSuite and TestCase share and add appropriate constants there as well.

@pekkaklarck
Copy link
Member Author

Hmm, it probably makes sense to add ModelObject.TASK constant as an alias for MobelObject.TEST.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant