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 APIs for generic storage capability #3

Open
pksol opened this issue Jun 28, 2021 · 4 comments
Open

Add APIs for generic storage capability #3

pksol opened this issue Jun 28, 2021 · 4 comments

Comments

@pksol
Copy link

pksol commented Jun 28, 2021

Allow tests to store state data that can be used in the future:

  • Add a "put" method which gets a key and data and stores that for the given test
  • Add a "get" method which gets a key and returns the previously stored data for the given test
  • Add a "state" attribute which tells the code if we're in recording (writing) mode or in fetching mode

This API is very generic and can be used to implement many capabilities.
For example, say I want to make sure my test performance doesn't degrade over time: I would store an initial benchmark in the recording phase and validate against that benchmark in future runs.

@pohmelie
Copy link
Owner

How this will looks like? Something like

if state is State.RECORDING:
    data = foo()
    put("data", data)
else:
    data = get("data")

I see many problems with such approach, and maybe this should be different lib, I'm not sure.

@pksol
Copy link
Author

pksol commented Jun 30, 2021

Yes, this is the basic idea I had.

It could be a separate lib since it's a more general usage than this library, maybe pytest-automock can even depend on that new library as the storage provider.

What are the problems you see with this approach?

@pohmelie
Copy link
Owner

pohmelie commented Oct 8, 2021

The problem here, as I see it, that state can be used only in tests code itself, not in the code of library or project. Lets say I want to mock something with same mechanic as it is in automock. I need to bring some test-aware code into my library to dispatch by state. automock, instead do it implicitly, so your project code do not know is it a recording or is it a replaying mode.

@pksol
Copy link
Author

pksol commented Oct 9, 2021

I was thinking that when someone wants to use this capability, the code that touches state would be mostly in the fixtures, so individual tests are not aware of the state most of the time.

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

No branches or pull requests

2 participants