Skip to content

Commit 6f33e86

Browse files
authored
Merge branch 'master' into antonpirker/openai-agents-guardrail-span
2 parents d1e56ad + d9811fe commit 6f33e86

File tree

22 files changed

+686
-140
lines changed

22 files changed

+686
-140
lines changed

CONTRIBUTING.md

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,19 +74,37 @@ That's it. You should be ready to make changes, run tests, and make commits! If
7474

7575
## Running Tests
7676

77-
You can run all tests with the following command:
77+
We test against a number of Python language and library versions, which are automatically generated and stored in the [tox.ini](tox.ini) file. The `envlist` defines the environments you can choose from when running tests, and correspond to package versions and environment variables. The `TESTPATH` environment variable, in turn, determines which tests are run.
78+
79+
The tox CLI tool is required to run the tests locally. Follow [the installation instructions](https://tox.wiki/en/latest/installation.html) for tox. Dependencies are installed for you when you run the command below, but _you_ need to bring an appropriate Python interpreter.
80+
81+
[Pyenv](https://github.com/pyenv/pyenv) is a cross-platform utility for managing Python versions. You can also use a conventional package manager, but not all versions may be distributed in the package manager of your choice. For macOS, Versions 3.8 and up can be installed with Homebrew.
82+
83+
An environment consists of the Python major and minor version and the library name and version. The exception to the rule is that you can provide `common` instead of the library information. The environments tied to a specific library usually run the corresponding test suite, while `common` targets all tests but skips those that require uninstalled dependencies.
84+
85+
To run Celery tests for version v5.5.3 of its Python library using a 3.12 interpreter, use
7886

7987
```bash
80-
pytest tests/
88+
tox -p auto -o -e py3.12-celery-v5.5.3
8189
```
8290

83-
If you would like to run the tests for a specific integration, use a command similar to the one below:
91+
or to use the `common` environment, run
8492

8593
```bash
86-
pytest -rs tests/integrations/flask/ # Replace "flask" with the specific integration you wish to test
94+
tox -p auto -o -e py3.12-common
8795
```
8896

89-
**Hint:** Tests of integrations need additional dependencies. The switch `-rs` will show you why tests were skipped and what dependencies you need to install for the tests to run. (You can also consult the [tox.ini](tox.ini) file to see what dependencies are installed for each integration)
97+
To select specific tests, you can forward arguments to `pytest` like so
98+
99+
```bash
100+
tox -p auto -o -e py3.12-celery-v5.5.3 -- -k test_transaction_events
101+
```
102+
103+
In general, you use
104+
105+
```bash
106+
tox -p auto -o -e <tox_env> -- <pytest_args>
107+
```
90108

91109
## Adding a New Integration
92110

scripts/populate_tox/README.md

Lines changed: 24 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ The `populate_tox.py` script fills out the auto-generated part of that template.
1616
It does this by querying PyPI for each framework's package and its metadata and
1717
then determining which versions make sense to test to get good coverage.
1818

19-
The lowest supported and latest version of a framework are always tested, with
20-
a number of releases in between:
19+
By default, the lowest supported and latest version of a framework are always
20+
tested, with a number of releases in between:
2121
- If the package has majors, we pick the highest version of each major.
2222
- If the package doesn't have multiple majors, we pick two versions in between
2323
lowest and highest.
@@ -34,7 +34,8 @@ the main package (framework, library) to test with; any additional test
3434
dependencies, optionally gated behind specific conditions; and optionally
3535
the Python versions to test on.
3636

37-
Constraints are defined using the format specified below. The following sections describe each key.
37+
Constraints are defined using the format specified below. The following sections
38+
describe each key.
3839

3940
```
4041
integration_name: {
@@ -43,7 +44,7 @@ integration_name: {
4344
rule1: [package1, package2, ...],
4445
rule2: [package3, package4, ...],
4546
},
46-
"python": python_version_specifier,
47+
"python": python_version_specifier | dict[package_version_specifier, python_version_specifier],
4748
"include": package_version_specifier,
4849
"integration_name": integration_name,
4950
"num_versions": int,
@@ -102,15 +103,14 @@ Python versions, you can say:
102103
...
103104
}
104105
```
106+
105107
This key is optional.
106108

107109
### `python`
108110

109111
Sometimes, the whole test suite should only run on specific Python versions.
110-
This can be achieved via the `python` key.
111-
112-
There are two variants how to define the Python versions to run the test suite
113-
on.
112+
This can be achieved via the `python` key. There are two variants how to define
113+
the Python versions to run the test suite on.
114114

115115
If you want the test suite to only be run on specific Python versions, you can
116116
set `python` to a version specifier. For example, if you want AIOHTTP tests to
@@ -142,18 +142,17 @@ say:
142142
The `python` key is optional, and when possible, it should be omitted. The script
143143
should automatically detect which Python versions the package supports. However,
144144
if a package has broken metadata or the SDK is explicitly not supporting some
145-
packages on specific Python versions (because of, for example, broken context
146-
vars), the `python` key can be used.
145+
packages on specific Python versions, the `python` key can be used.
147146

148147
### `include`
149148

150-
Sometimes we only want to consider testing some specific versions of packages.
151-
For example, the Starlite package has two alpha prereleases of version 2.0.0, but
152-
we do not want to test these, since Starlite 2.0 was renamed to Litestar.
149+
Sometimes we only want to test specific versions of packages. For example, the
150+
Starlite package has two alpha prereleases of version 2.0.0, but we do not want
151+
to test these, since Starlite 2.0 was renamed to Litestar.
153152

154153
The value of the `include` key expects a version specifier defining which
155154
versions should be considered for testing. For example, since we only want to test
156-
versions below 2.x in Starlite, we can use
155+
versions below 2.x in Starlite, we can use:
157156

158157
```python
159158
"starlite": {
@@ -178,13 +177,21 @@ be expressed like so:
178177

179178
Sometimes, the name of the test suite doesn't match the name of the integration.
180179
For example, we have the `openai_base` and `openai_notiktoken` test suites, both
181-
of which are actually testing the `openai` integration. If this is the case, you can use the `integration_name` key to define the name of the integration. If not provided, it will default to the name of the test suite.
180+
of which are actually testing the `openai` integration. If this is the case, you
181+
can use the `integration_name` key to define the name of the integration. If not
182+
provided, it will default to the name of the test suite.
182183

183-
Linking an integration to a test suite allows the script to access integration configuration like for example the minimum version defined in `sentry_sdk/integrations/__init__.py`.
184+
Linking an integration to a test suite allows the script to access integration
185+
configuration like, for example, the minimum supported version defined in
186+
`sentry_sdk/integrations/__init__.py`.
184187

185188
### `num_versions`
186189

187-
With this option you can tweak the default version picking behavior by specifying how many package versions should be tested. It accepts an integer equal to or greater than 2, as the oldest and latest supported versions will always be picked. Additionally, if there is a recent prerelease, it'll also always be picked (this doesn't count towards `num_versions`).
190+
With this option you can tweak the default version picking behavior by specifying
191+
how many package versions should be tested. It accepts an integer equal to or
192+
greater than 2, as the oldest and latest supported versions will always be
193+
picked. Additionally, if there is a recent prerelease, it'll also always be
194+
picked (this doesn't count towards `num_versions`).
188195

189196

190197
## How-Tos
@@ -202,26 +209,3 @@ With this option you can tweak the default version picking behavior by specifyin
202209
`scripts/split_tox_gh_actions/split_tox_gh_actions.py`.
203210
4. Add the `TESTPATH` for the test suite in `tox.jinja`'s `setenv` section.
204211
5. Run `scripts/generate-test-files.sh` and commit the changes.
205-
206-
### Migrate a test suite to populate_tox.py
207-
208-
A handful of integration test suites are still hardcoded. The goal is to migrate
209-
them all to `populate_tox.py` over time.
210-
211-
1. Remove the integration from the `IGNORE` list in `populate_tox.py`.
212-
2. Remove the hardcoded entries for the integration from the `envlist` and `deps` sections of `tox.jinja`.
213-
3. Run `scripts/generate-test-files.sh`.
214-
4. Run the test suite, either locally or by creating a PR.
215-
5. Address any test failures that happen.
216-
217-
You might have to introduce additional version bounds on the dependencies of the
218-
package. Try to determine the source of the failure and address it.
219-
220-
Common scenarios:
221-
- An old version of the tested package installs a dependency without defining
222-
an upper version bound on it. A new version of the dependency is installed that
223-
is incompatible with the package. In this case you need to determine which
224-
versions of the dependency don't contain the breaking change and restrict this
225-
in `TEST_SUITE_CONFIG`.
226-
- Tests are failing on an old Python version. In this case first double-check
227-
whether we were even testing them on that version in the original `tox.ini`.

0 commit comments

Comments
 (0)