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

Improve context storage to share data through whole run #396

Merged

Conversation

legnadev
Copy link
Member

@legnadev legnadev commented Jun 27, 2024

Improved the managing of storages:

  • Added run_storage to store information during the whole test execution
  • Storages chained to be able to get the information always from context.storage / [CONTEXT:]
  • In steps, be able to store values into desire storage by using [key], [FEATURE:key] and [RUN:key]. Example:
    • I store in key "store_key" the value "XXX"
    • I store in key "[FEATURE:store_key]" the value "XXX"
    • I store in key "[RUN:store_key]" the value "XXX"
  • Implemented new method store_key_in_storageto manage it

@legnadev legnadev self-assigned this Jun 27, 2024
@rgonalo rgonalo requested a review from a team June 27, 2024 10:16
Copy link
Member

@pabloge pabloge left a comment

Choose a reason for hiding this comment

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

Please provide motivation and detailed description.

@legnadev legnadev added the wip label Jun 27, 2024
@legnadev legnadev removed the wip label Jun 27, 2024
@legnadev legnadev requested a review from pabloge June 27, 2024 15:08
Copy link
Contributor

Choose a reason for hiding this comment

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

LGTM

Copy link
Member Author

Choose a reason for hiding this comment

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

Redesigned again with Chainmap, this time making sure it works, just to give more information:
ChainMap unifies, or links, the 3 context dictionaries into one

Considering we have a mapchain( Dict1, Dict2, Dict3) where dicts are storage, feature and run:

  • If i get a value with context.storage["key"] the first key found in the 3 dictionaries will be retrieved, accesing them by order from left to right. So if we have a duplicated key in storate and run storage, it will get the storage one. -> To avoid this, the programmer should be responsible of where the key is added, but we handle it if you use the store_in_context function.
  • If i set a value into context.storage, it will be stored in the first dictionary always, so it will always be stored in context.storage so this leaves the context.storage to work as the previous behavior as desired and expected.
  • context.storage and run_storage are linked in before all, so instead of a chainmap, any change you do to storage is stored in run, which is an expected behaviour since the only existant context in before all is the run_storage.

Copy link
Contributor

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@pabloge pabloge left a comment

Choose a reason for hiding this comment

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

The new logic based on ChainMaps to search for storage keys is OK.

The new function to store values in one place or another depending on their prefix does not seem like a good programming practice to me, especially in the context of BDD, and I would remove it.

toolium/behave/environment.py Outdated Show resolved Hide resolved
Copy link

codeclimate bot commented Sep 10, 2024

Code Climate has analyzed commit 8c9c7b1 and detected 0 issues on this pull request.

View more on Code Climate.

@legnadev legnadev merged commit 496dfda into Telefonica:master Sep 10, 2024
14 checks passed
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.

4 participants