-
-
Notifications
You must be signed in to change notification settings - Fork 196
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
[Question] Common objects at the root of test cases #774
Comments
For the first part (using the common 'fastapi' tag) you can either define it in one test at the top of the file and reuse it in other tests using a yaml anchor like in the MQTT tests tavern/example/mqtt/test_mqtt.tavern.yaml Lines 8 to 17 in 1559ce8
def pytest_tavern_beta_before_every_test_run(test_dict, variables):
test_dict["fastapi"] = {"app": {"location": "tests.fastapi_test_app"}} and this should automatically add it into every test. For the second one (setting the 'strict' defaults) it can be done in your pytest.ini file like this: [pytest]
tavern-strict=
headers:off
json:off
# other options... |
Right, but is there a way to refactor tavern/example/mqtt/test_mqtt.tavern.yaml Lines 8 to 17 in 1559ce8
Assume that I come to realize that host, port and client_id needs to be changed.
that's an alternative way to do it, although it introduces some "magic" (the tester has to know the YAML file isn't exhaustive and there's additional configuration that is being done but I can put this in the documentation) - just wondering if a more explicit method like in above is possible (even if additional effort/work would be needed to do this)? Another question: Why did you name the hook |
You should be able to use the fastapi:
!include fastapi-settings.yaml and have this in the app:
location: "tests.fastapi_test_app" I've tested this with the mqtt settings and it works so it should work for you too. |
I am using a plugin
tavern_fastapi
and that requires me to repeat this snippet across test files:Now I know how to include common variables like so:
but if I wanted to include the first snippet across tests, is there a way to do so?
A complete
test_a.tavern.yaml
look like:The text was updated successfully, but these errors were encountered: