[BUG] Ascii can not be valid when generate test case with schemathesis
jiejunsailor opened this issue · comments
Checklist
- I checked the FAQ section of the documentation
- I looked for similar issues in the issue tracker
- I am using the latest version of Schemathesis
Describe the bug
when I use Schemathesis to generate test case by setting as below, which avoid generating test cases with symbols that are not recognizable due to using utf-8 for string generation.
generation_config=GenerationConfig(allow_x00=False, codec='ascii'),
But after I run it with my own schema, the screenshot of the generated test cases still contains unreadable characters, such as the text highlighted in the circle below.
To Reproduce
🚨 Mandatory 🚨: Steps to reproduce the behavior:
- Run this command 'run' in pycharm environment
- See result above screenshot.
Clearly describe your expected outcome.
I would like the generated test case to not contain characters that are difficult to understand.
Environment
- OS: [e.g. Linux or Windows]
- Python version: [3.9.18]
- Schemathesis version: [3.25.4]
- Spec version: [e.g. Open API 3.0.2]
Additional context
Below information is excerpted from help documentation.
Generating strings
In Schemathesis, you can control how strings are generated:
allow_x00 (default True): Determines whether to allow the generation of \x00 bytes within strings. It is useful to avoid rejecting tests as invalid by some web servers.
codec (default utf-8): Specifies the codec used for generating strings. It helps if you need to restrict the inputs to, for example, the ASCII range.
Global configuration
CLI:
$ st run --generation-allow-x00=false ...
$ st run --generation-codec=ascii ...
Python:
import schemathesis
from schemathesis import GenerationConfig
schema = schemathesis.from_uri(
"https://example.schemathesis.io/openapi.json",
generation_config=GenerationConfig(allow_x00=False, codec='ascii'),
)
This configuration sets the string generation to disallow \x00 bytes and use the ASCII codec for all strings.
Closing in favor of #2089