You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: .changeset/live_tests.md
+4-4
Original file line number
Diff line number
Diff line change
@@ -2,13 +2,13 @@
2
2
default: minor
3
3
---
4
4
5
-
# New categories of end-to-end tests
5
+
# Functional tests
6
6
7
-
Automated tests have been extended to include two new types of tests:
7
+
Automated tests have been extended to include a new category of "functional" tests, in [`end_to_end_tests/functional_tests`](./end_to_end_tests/functional_tests). These are of two kinds:
8
8
9
-
1. Happy-path tests that run the generator from an inline API document and then actually import and execute the generated code. See [`end_to_end_tests/generated_code_live_tests`](./end_to_end_tests/generated_code_live_tests).
9
+
1. Happy-path tests that run the generator from an inline API document and then actually import and execute the generated code.
10
10
2. Warning/error condition tests that run the generator from an inline API document that contains something invalid, and make assertions about the generator's output.
11
11
12
-
These provide more efficient and granular test coverage than the "golden record"-based end-to-end tests, and also replace some tests that were previously being done against low-level implementation detailsin `tests/unit`.
12
+
These provide more efficient and granular test coverage than the "golden record"-based end-to-end tests. Also, the low-level unit tests in `tests`, which are dependent on internal implementation details, can now in many cases be replaced by functional tests.
13
13
14
14
This does not affect any runtime functionality of openapi-python-client.
Copy file name to clipboardExpand all lines: CONTRIBUTING.md
+5-6
Original file line number
Diff line number
Diff line change
@@ -69,21 +69,20 @@ There are 4 types of snapshots generated right now, you may have to update only
69
69
3.`test_custom_templates` are used with `baseline_openapi_3.0.json` to generate `custom-templates-golden-record` for testing custom templates
70
70
4.`3.1_specific.openapi.yaml` is used to generate `test-3-1-golden-record` and test 3.1-specific features (things which do not have a 3.0 equivalent)
71
71
72
-
#### Unit tests of generated code
72
+
#### Functional tests
73
73
74
-
These verify the runtime behavior of the generated code, without making assertions about the exact implementation of the code. For instance, they can verify that JSON data is correctly decoded into model class attributes.
74
+
These are black-box tests that verify the runtime behavior of generated code, as well as the generator's validation behavior. For instance, they can verify that JSON data is correctly decoded into model class attributes, or that the generator will emit an appropriate warning for an invalid spec.
75
75
76
-
The tests run the generator against a small API spec (defined inline for each test class), and then import and execute the generated code. This can sometimes identify issues with validation logic, module imports, etc., that might be harder to diagnose via the snapshot tests, especially during development of a new feature.
76
+
This can sometimes identify issues with error handling, validation logic, module imports, etc., that might be harder to diagnose via the snapshot tests, especially during development of a new feature.
77
77
78
-
See [`end_to_end_tests/generated_code_live_tests`](./end_to_end_tests/generated_code_live_tests).
78
+
See [`end_to_end_tests/functional_tests`](./end_to_end_tests/functional_tests).
79
79
80
80
#### Other unit tests
81
81
82
82
These include:
83
83
84
84
* Regular unit tests of basic pieces of fairly self-contained low-level functionality, such as helper functions. These are implemented in the `tests/unit` directory, using the `pytest` framework.
85
-
* End-to-end tests of invalid spec conditions, where we run the generator against a small spec with some problem, and expect it to print warnings/errors rather than generating code. These are implemented in `end_to_end_tests/generator_errors_and_warnings`.
86
-
* Older-style unit tests of low-level functions like `property_from_data` that have complex behavior. These are brittle and difficult to maintain, and should not be used going forward. Instead, use either unit tests of generated code (to test happy paths), or end-to-end tests of invalid spec conditions (to test for warnings/errors), as described above.
85
+
* Older-style unit tests of low-level functions like `property_from_data` that have complex behavior. These are brittle and difficult to maintain, and should not be used going forward. Instead, they should be migrated to functional tests.
Copy file name to clipboardExpand all lines: end_to_end_tests/functional_tests/README.md
+23-2
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,14 @@
1
-
## The `generated_code_live_tests` module
1
+
## The `functional_tests` module
2
2
3
-
These are end-to-end tests which run the code generator command, but unlike the other tests in `end_to_end_tests`, they are also unit tests _of the behavior of the generated code_.
3
+
These are end-to-end tests which run the client generator against many small API documents that are specific to various test cases.
4
+
5
+
Rather than testing low-level implementation details (like the unit tests in `tests`), or making assertions about the exact content of the generated code (like the "golden record"-based end-to-end tests), these treat both the generator and the generated code as black boxes and make assertions about their behavior.
6
+
7
+
The tests are in two submodules:
8
+
9
+
# `generated_code_execution`
10
+
11
+
These tests use valid API specs, and after running the generator, they _import and execute_ pieces of the generated code to verify that it actually works at runtime.
These run the generator with an invalid API spec and make assertions about the warning/error output. Some of these invalid conditions are expected to only produce warnings about the affected schemas, while others are expected to produce fatal errors that terminate the generator.
48
+
49
+
For warning conditions, each test class follows this pattern:
50
+
51
+
- Call `inline_spec_should_cause_warnings`, providing an inline API spec (JSON or YAML). If there are several test methods in the class using the same spec, use a fixture with scope "class" so the generator is only run once.
52
+
- Use `assert_bad_schema_warning` to parse the output and check for a specific warning message for a specific schema name.
53
+
54
+
Or, for fatal error conditions:
55
+
56
+
- Call `inline_spec_should_fail`, providing an inline API spec (JSON or YAML).
0 commit comments