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

Alternative API for stateful tests in Python #737

Closed
Stranger6667 opened this issue Sep 24, 2020 · 5 comments
Closed

Alternative API for stateful tests in Python #737

Stranger6667 opened this issue Sep 24, 2020 · 5 comments
Assignees
Labels
Difficulty: Hard Complex, needs deep understanding Priority: Medium Planned for regular releases

Comments

@Stranger6667
Copy link
Member

Stranger6667 commented Sep 24, 2020

Even though now all stateful tests are separate pytest items it might be better to run all of them in a single test function. Something like this:

@schema.parametrize()
def test_api(case):
    for step in case.get_stateful_tests():
        response = step.call()
        step.validate_response(response)

It might be much easier to implement since there will be no need to integrate it with pytest itself. Also - there will be no mangled execution statistic in the pytest output because it is a single test, there will be no problems with changing hypothesis settings in subsequent steps, etc

@Stranger6667 Stranger6667 added Difficulty: Hard Complex, needs deep understanding Priority: Medium Planned for regular releases Type: Enhancement labels Sep 24, 2020
@Stranger6667 Stranger6667 self-assigned this Sep 24, 2020
@Zac-HD
Copy link

Zac-HD commented Sep 29, 2020

Have you seen REST-ler? It doesn't look like it's open source, but there are some nice ideas about inferring dependencies and order of calls that could enhance stateful mode 🙂

Building schemathesis' stateful mode on top of Hypothesis' RuleBasedStateMachine would be really nice - especially with {A,W}SGI mode so you can reset the app between test runs. Longer-term that would even allow coverage-guided fuzzing for webapps...

@Stranger6667
Copy link
Member Author

Yep, I actually created this issue after reading that paper :) The current implementation with pytest is quite clunky - it modifies some internals between test executions. I hope that this implementation will be re-iterated in the next major release to incorporate ideas from REST-let & #520.

Building schemathesis' stateful mode on top of Hypothesis' RuleBasedStateMachine would be really nice

I tried it a couple of times but decided to go with a more straightforward approach - incorporating RuleBasedStateMachine will require some significant refactorings, but I think it worth it in the long run :)

Longer-term that would even allow coverage-guided fuzzing for webapps...

That sounds really cool! I ran some experiments with Hypothesis' target, and it was promising :) But it is still a huge area to research

@Stranger6667
Copy link
Member Author

As a sidenote

HypoFuzz looks awesome to me :) Wondering what bugs were found in hypothesis-jsonschema as mentioned in the text above the dashboard :)

@Zac-HD
Copy link

Zac-HD commented Sep 30, 2020

@Stranger6667
Copy link
Member Author

Implemented in #805 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Difficulty: Hard Complex, needs deep understanding Priority: Medium Planned for regular releases
Projects
None yet
Development

No branches or pull requests

2 participants