Skip to content

Commit 943607a

Browse files
beniwohlibasepi
andauthored
added section on adding matrix tests to CONTRIBUTING.md (#967)
Co-authored-by: Colton Myers <colton.myers@gmail.com>
1 parent 0e4f500 commit 943607a

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

CONTRIBUTING.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,65 @@ be used. For example, whenever a test has `elasticapm_client` as an argument,
108108
that is a fixture which is defined
109109
[here](https://github.com/elastic/apm-agent-python/blob/ed4ce5fd5db3cc091a54d3328384fbce62635bbb/tests/fixtures.py#L150).
110110

111+
#### Adding new instrumentations to the matrix build
112+
113+
For tests that require external dependencies like databases, or for testing different versions of the same library,
114+
we use a matrix build that leverages Docker and docker-compose.
115+
116+
The setup requires a little bit of boilerplate to get started.
117+
In this example, we will create an instrumentation for the "foo" database, by instrumenting its Python driver, `foodriver`.
118+
119+
1. mark your tests with a pytest marker that describes the new instrumentation at the top of your tests file:
120+
121+
pytestmark = pytest.mark.foo
122+
123+
`pytestmark` can also be a list if you need to define more than one mark (e.g. to mark tests as integration tests):
124+
125+
pytestmark = [pytest.mark.foo, pytest.mark.integrationtest]
126+
127+
1. make sure to use `pytest.importorskip` to import any dependencies that are only required by your tests:
128+
129+
foodriver = pytest.importorskip("foodriver")
130+
131+
1. Create one or more requirements files in `tests/requirements` that list the dependencies that are to be installed specifically for your tests:
132+
To only test the newest version of the library, create a file `tests/requirements/reqs-foo-newest.txt` and add something like this to it:
133+
134+
foodriver
135+
-r reqs-base.txt
136+
137+
This tells the matrix runner to install the newest version of `foodriver`, as well as the base requirements needed to run the test suite.
138+
To test more than one version of the library, create additional `reqs-foo-X.Y.txt` files with specific versions of your instrumented package.
139+
140+
1. Create a file called `foo.sh` in `tests/scripts/envs/foo.sh`.
141+
Here you can define environment variables that are required to run your tests.
142+
As a minimum, you'll have to set the `PYTEST_MARKER` variable to the same value you used above for the pytest marker, e.g.
143+
144+
export PYTEST_MARKER="-m foo"
145+
146+
1. Add entries in `.ci/jenkins_framework.yml` (for pull requests) and `.ci/jenkins_framework_full.yml` (for nightly builds).
147+
Generally, we only test the newest version of an instrumentation with every pull request:
148+
149+
- foo-newest
150+
151+
To test other versions in the nightly build, add them to `.ci/jenkins_framework_full.yml`.
152+
153+
1. OPTIONAL: If you need a real service to test against (e.g. an actual foo database), add an entry in `tests/docker-compose.yml` under `services`:
154+
155+
foo:
156+
image: foobase:latest
157+
158+
You'll also have to add a `DOCKER_DEPS` environment variable to `tests/scripts/envs/foo.sh` which tells the matrix
159+
to spin up the given docker-compose service before running your tests.
160+
You may also need to add things like hostname configuration here.
161+
162+
DOCKER_DEPS="foo"
163+
FOO_CONNECTION_URL="http://foo:4711"
164+
165+
1. OPTIONAL: If your instrumented package does not support all Python versions we test with, you can exclude certain combinations by adding them to `.ci/jenkins_exclude.yml`:
166+
167+
- PYTHON_VERSION: python-3.5 # foo doesn't support Python 3.5
168+
FRAMEWORK: foo-newest
169+
111170
### Workflow
112171

113172
All feature development and most bug fixes hit the master branch first.

0 commit comments

Comments
 (0)