-
-
Notifications
You must be signed in to change notification settings - Fork 165
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
[BUG] Issue with --hypothesis-phases=explicit and GET requests without parameters #1728
Comments
Hi @Stranger6667, this issue is somewhat painful and stops us from transitioning from dredd to schemathesis with piece of mind. I'd be willing to try to put together a PR if you could give some pointers where to start as I'm not familiar with schemathesis/hypothesis internals. |
Hi @IvanRibakov My current thinking is that the interface of Schemathesis CLI is misleading in this regard, or the purpose of the "explicit" phase does not match the expectations. Essentially, providing My reading of this issue (and, in fact, a few other similar issues) is that often users want to run all explicit examples and generate a test case when an API operation does not declare any examples. Such kind of behavior does not clearly fit the concept of phases, as it involves 2 phases ( The following is a separate block of information, but I want to mention it as I think it gives a bit more context. The whole area of how Schemathesis handles explicit examples is a bit hacky and involves data generation for required parameters that are missing in examples. It also limits the number of parameter combinations because of combinatorial blowup - but there are no heuristics or anything to choose what combinations should get to the final examples list. However, Hypothesis has such heuristics and it might be better to offload this completely to data generation, but then it won't be a quick run over explicit examples anymore. In any event, I think that the aforementioned expectation is completely legit, but it might be better to eventually add a new concept of However, it seems like the before_add_examples hook could work here: import schemathesis
from schemathesis import Case
import hypothesis
@schemathesis.hook
def before_add_examples(context, examples) -> None:
if not examples:
strategy = context.operation.as_strategy()
# Adopted from Hypothesis source code
@hypothesis.given(strategy)
@hypothesis.settings(
database=None,
max_examples=1,
deadline=None,
verbosity=hypothesis.Verbosity.quiet,
phases=(hypothesis.Phase.generate,),
suppress_health_check=list(hypothesis.HealthCheck),
)
def example_generating_inner_function(ex):
examples.append(ex)
example_generating_inner_function() Maybe the path forward could be to use the snippet above as some P.S. I noticed that some code samples in the linked documentation page are missing the |
@Stranger6667 Thank you for the expanded answer. Now I can see why you've applied "Needs Design" label. I'm afraid working on a proper solution according to the vision that you laid out above is out of my depth, but I have to say that the workaround that you mentioned works well for us - thanks for sharing it! |
You're very welcome! No worries, I am going to make a PR for this |
…ack explicit examples Ref: #1728
…ack explicit examples Ref: #1728
I added |
Description:
When using the --hypothesis-phases=explicit parameter in SCHEMATHESIS, it has been observed that GET requests without parameters are being skipped during testing. This creates a problem for users as they have to resort to adding fake parameters and then try to exclude them from the documentation, which is not an optimal solution.
The example that reproduces the error:
Example with fake param:
To Reproduce
Steps to reproduce the behavior:
Add a get petition without params and use the --hypothesis-phases=explicit configuration.
Schemathesis will skip this test.
Expected behavior
Execute gets requests without params.
Environment :
Docker container, image: schemathesis/schemathesis:stable
The text was updated successfully, but these errors were encountered: