Skip to content

Commit 3715989

Browse files
sorasfulalexmojaki
andauthored
Parallelize tests using pytest-xdist (#820)
Co-authored-by: Alex Hall <[email protected]>
1 parent 7dd0382 commit 3715989

File tree

5 files changed

+64
-37
lines changed

5 files changed

+64
-37
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ typecheck:
3030

3131
.PHONY: test # Run the tests
3232
test:
33-
uv run --no-sync coverage run -m pytest
33+
uv run --no-sync coverage run -m pytest -n auto --dist=loadgroup
3434

3535
.PHONY: generate-stubs # Generate stubs for logfire-api
3636
generate-stubs:

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ dev = [
165165
"boto3 >= 1.28.57",
166166
"botocore >= 1.31.57",
167167
"greenlet >= 3.1.1",
168+
"pytest-xdist>=3.6.1",
168169
]
169170
docs = [
170171
"black>=23.12.0",

tests/otel_integrations/test_sqlalchemy.py

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def sqlite_engine(path: Path) -> Iterator[Engine]:
4545

4646

4747
def test_sqlalchemy_instrumentation(exporter: TestExporter):
48-
with sqlite_engine(Path('example.db')) as engine:
48+
with sqlite_engine(Path('example1.db')) as engine:
4949
logfire.instrument_sqlalchemy(engine=engine)
5050

5151
Base.metadata.create_all(engine)
@@ -69,13 +69,13 @@ def test_sqlalchemy_instrumentation(exporter: TestExporter):
6969
'attributes': {
7070
'logfire.span_type': 'span',
7171
'logfire.msg': 'connect',
72-
'db.name': 'example.db',
72+
'db.name': 'example1.db',
7373
'db.system': 'sqlite',
7474
'logfire.level_num': 5,
7575
},
7676
},
7777
{
78-
'name': 'PRAGMA example.db',
78+
'name': 'PRAGMA example1.db',
7979
'context': {'trace_id': 2, 'span_id': 3, 'is_remote': False},
8080
'parent': None,
8181
'start_time': 3000000000,
@@ -85,11 +85,11 @@ def test_sqlalchemy_instrumentation(exporter: TestExporter):
8585
'logfire.msg': 'PRAGMA main.table_info("auth_records")',
8686
'db.statement': 'PRAGMA main.table_info("auth_records")',
8787
'db.system': 'sqlite',
88-
'db.name': 'example.db',
88+
'db.name': 'example1.db',
8989
},
9090
},
9191
{
92-
'name': 'PRAGMA example.db',
92+
'name': 'PRAGMA example1.db',
9393
'context': {'trace_id': 3, 'span_id': 5, 'is_remote': False},
9494
'parent': None,
9595
'start_time': 5000000000,
@@ -99,11 +99,11 @@ def test_sqlalchemy_instrumentation(exporter: TestExporter):
9999
'logfire.msg': 'PRAGMA temp.table_info("auth_records")',
100100
'db.statement': 'PRAGMA temp.table_info("auth_records")',
101101
'db.system': 'sqlite',
102-
'db.name': 'example.db',
102+
'db.name': 'example1.db',
103103
},
104104
},
105105
{
106-
'name': 'CREATE example.db',
106+
'name': 'CREATE example1.db',
107107
'context': {'trace_id': 4, 'span_id': 7, 'is_remote': False},
108108
'parent': None,
109109
'start_time': 7000000000,
@@ -116,7 +116,7 @@ def test_sqlalchemy_instrumentation(exporter: TestExporter):
116116
""",
117117
'db.statement': '\nCREATE TABLE auth_records (\n\tid INTEGER NOT NULL, \n\tnumber INTEGER NOT NULL, \n\tcontent VARCHAR NOT NULL, \n\tPRIMARY KEY (id)\n)\n\n',
118118
'db.system': 'sqlite',
119-
'db.name': 'example.db',
119+
'db.name': 'example1.db',
120120
},
121121
},
122122
{
@@ -128,13 +128,13 @@ def test_sqlalchemy_instrumentation(exporter: TestExporter):
128128
'attributes': {
129129
'logfire.span_type': 'span',
130130
'logfire.msg': 'connect',
131-
'db.name': 'example.db',
131+
'db.name': 'example1.db',
132132
'db.system': 'sqlite',
133133
'logfire.level_num': 5,
134134
},
135135
},
136136
{
137-
'name': 'select example.db',
137+
'name': 'select example1.db',
138138
'context': {'trace_id': 6, 'span_id': 11, 'is_remote': False},
139139
'parent': None,
140140
'start_time': 11000000000,
@@ -144,11 +144,11 @@ def test_sqlalchemy_instrumentation(exporter: TestExporter):
144144
'logfire.msg': 'select * from auth_records',
145145
'db.statement': 'select * from auth_records',
146146
'db.system': 'sqlite',
147-
'db.name': 'example.db',
147+
'db.name': 'example1.db',
148148
},
149149
},
150150
{
151-
'name': 'INSERT example.db',
151+
'name': 'INSERT example1.db',
152152
'context': {'trace_id': 7, 'span_id': 13, 'is_remote': False},
153153
'parent': None,
154154
'start_time': 13000000000,
@@ -158,7 +158,7 @@ def test_sqlalchemy_instrumentation(exporter: TestExporter):
158158
'logfire.msg': 'INSERT INTO auth_records (id, number, content) VALUES (?, ?, ?)',
159159
'db.statement': 'INSERT INTO auth_records (id, number, content) VALUES (?, ?, ?)',
160160
'db.system': 'sqlite',
161-
'db.name': 'example.db',
161+
'db.name': 'example1.db',
162162
},
163163
},
164164
{
@@ -170,13 +170,13 @@ def test_sqlalchemy_instrumentation(exporter: TestExporter):
170170
'attributes': {
171171
'logfire.span_type': 'span',
172172
'logfire.msg': 'connect',
173-
'db.name': 'example.db',
173+
'db.name': 'example1.db',
174174
'db.system': 'sqlite',
175175
'logfire.level_num': 5,
176176
},
177177
},
178178
{
179-
'name': 'SELECT example.db',
179+
'name': 'SELECT example1.db',
180180
'context': {'trace_id': 9, 'span_id': 17, 'is_remote': False},
181181
'parent': None,
182182
'start_time': 17000000000,
@@ -186,11 +186,11 @@ def test_sqlalchemy_instrumentation(exporter: TestExporter):
186186
'logfire.msg': 'SELECT auth_recor…ds_content FROM auth_records WHERE …',
187187
'db.statement': 'SELECT auth_records.id AS auth_records_id, auth_records.number AS auth_records_number, auth_records.content AS auth_records_content \nFROM auth_records \nWHERE auth_records.id = ?',
188188
'db.system': 'sqlite',
189-
'db.name': 'example.db',
189+
'db.name': 'example1.db',
190190
},
191191
},
192192
{
193-
'name': 'DELETE example.db',
193+
'name': 'DELETE example1.db',
194194
'context': {'trace_id': 10, 'span_id': 19, 'is_remote': False},
195195
'parent': None,
196196
'start_time': 19000000000,
@@ -200,7 +200,7 @@ def test_sqlalchemy_instrumentation(exporter: TestExporter):
200200
'logfire.msg': 'DELETE FROM auth_records WHERE auth_records.id = ?',
201201
'db.statement': 'DELETE FROM auth_records WHERE auth_records.id = ?',
202202
'db.system': 'sqlite',
203-
'db.name': 'example.db',
203+
'db.name': 'example1.db',
204204
},
205205
},
206206
]
@@ -221,7 +221,7 @@ def sqlite_async_engine(path: Path) -> Iterator[AsyncEngine]:
221221

222222
@pytest.mark.anyio
223223
async def test_sqlalchemy_async_instrumentation(exporter: TestExporter):
224-
with sqlite_async_engine(Path('example.db')) as engine:
224+
with sqlite_async_engine(Path('example2.db')) as engine:
225225
logfire.instrument_sqlalchemy(engine=engine)
226226

227227
async with engine.begin() as conn:
@@ -246,13 +246,13 @@ async def test_sqlalchemy_async_instrumentation(exporter: TestExporter):
246246
'attributes': {
247247
'logfire.span_type': 'span',
248248
'logfire.msg': 'connect',
249-
'db.name': 'example.db',
249+
'db.name': 'example2.db',
250250
'db.system': 'sqlite',
251251
'logfire.level_num': 5,
252252
},
253253
},
254254
{
255-
'name': 'PRAGMA example.db',
255+
'name': 'PRAGMA example2.db',
256256
'context': {'trace_id': 2, 'span_id': 3, 'is_remote': False},
257257
'parent': None,
258258
'start_time': 3000000000,
@@ -262,11 +262,11 @@ async def test_sqlalchemy_async_instrumentation(exporter: TestExporter):
262262
'logfire.msg': 'PRAGMA main.table_info("auth_records")',
263263
'db.statement': 'PRAGMA main.table_info("auth_records")',
264264
'db.system': 'sqlite',
265-
'db.name': 'example.db',
265+
'db.name': 'example2.db',
266266
},
267267
},
268268
{
269-
'name': 'PRAGMA example.db',
269+
'name': 'PRAGMA example2.db',
270270
'context': {'trace_id': 3, 'span_id': 5, 'is_remote': False},
271271
'parent': None,
272272
'start_time': 5000000000,
@@ -276,11 +276,11 @@ async def test_sqlalchemy_async_instrumentation(exporter: TestExporter):
276276
'logfire.msg': 'PRAGMA temp.table_info("auth_records")',
277277
'db.statement': 'PRAGMA temp.table_info("auth_records")',
278278
'db.system': 'sqlite',
279-
'db.name': 'example.db',
279+
'db.name': 'example2.db',
280280
},
281281
},
282282
{
283-
'name': 'CREATE example.db',
283+
'name': 'CREATE example2.db',
284284
'context': {'trace_id': 4, 'span_id': 7, 'is_remote': False},
285285
'parent': None,
286286
'start_time': 7000000000,
@@ -290,7 +290,7 @@ async def test_sqlalchemy_async_instrumentation(exporter: TestExporter):
290290
'logfire.msg': 'CREATE TABLE auth_records ( id INTEGER … t VARCHAR NOT NULL, PRIMARY KEY (id)\n)',
291291
'db.statement': '\nCREATE TABLE auth_records (\n\tid INTEGER NOT NULL, \n\tnumber INTEGER NOT NULL, \n\tcontent VARCHAR NOT NULL, \n\tPRIMARY KEY (id)\n)\n\n',
292292
'db.system': 'sqlite',
293-
'db.name': 'example.db',
293+
'db.name': 'example2.db',
294294
},
295295
},
296296
{
@@ -302,13 +302,13 @@ async def test_sqlalchemy_async_instrumentation(exporter: TestExporter):
302302
'attributes': {
303303
'logfire.span_type': 'span',
304304
'logfire.msg': 'connect',
305-
'db.name': 'example.db',
305+
'db.name': 'example2.db',
306306
'db.system': 'sqlite',
307307
'logfire.level_num': 5,
308308
},
309309
},
310310
{
311-
'name': 'select example.db',
311+
'name': 'select example2.db',
312312
'context': {'trace_id': 6, 'span_id': 11, 'is_remote': False},
313313
'parent': None,
314314
'start_time': 11000000000,
@@ -318,11 +318,11 @@ async def test_sqlalchemy_async_instrumentation(exporter: TestExporter):
318318
'logfire.msg': 'select * from auth_records',
319319
'db.statement': 'select * from auth_records',
320320
'db.system': 'sqlite',
321-
'db.name': 'example.db',
321+
'db.name': 'example2.db',
322322
},
323323
},
324324
{
325-
'name': 'INSERT example.db',
325+
'name': 'INSERT example2.db',
326326
'context': {'trace_id': 7, 'span_id': 13, 'is_remote': False},
327327
'parent': None,
328328
'start_time': 13000000000,
@@ -332,7 +332,7 @@ async def test_sqlalchemy_async_instrumentation(exporter: TestExporter):
332332
'logfire.msg': 'INSERT INTO auth_records (id, number, content) VALUES (?, ?, ?)',
333333
'db.statement': 'INSERT INTO auth_records (id, number, content) VALUES (?, ?, ?)',
334334
'db.system': 'sqlite',
335-
'db.name': 'example.db',
335+
'db.name': 'example2.db',
336336
},
337337
},
338338
{
@@ -344,13 +344,13 @@ async def test_sqlalchemy_async_instrumentation(exporter: TestExporter):
344344
'attributes': {
345345
'logfire.span_type': 'span',
346346
'logfire.msg': 'connect',
347-
'db.name': 'example.db',
347+
'db.name': 'example2.db',
348348
'db.system': 'sqlite',
349349
'logfire.level_num': 5,
350350
},
351351
},
352352
{
353-
'name': 'SELECT example.db',
353+
'name': 'SELECT example2.db',
354354
'context': {'trace_id': 9, 'span_id': 17, 'is_remote': False},
355355
'parent': None,
356356
'start_time': 17000000000,
@@ -362,11 +362,11 @@ async def test_sqlalchemy_async_instrumentation(exporter: TestExporter):
362362
SELECT auth_records.id AS auth_records_id, auth_records.number AS auth_records_number, auth_records.content AS auth_records_content \nFROM auth_records \nWHERE auth_records.id = ?\
363363
""",
364364
'db.system': 'sqlite',
365-
'db.name': 'example.db',
365+
'db.name': 'example2.db',
366366
},
367367
},
368368
{
369-
'name': 'DELETE example.db',
369+
'name': 'DELETE example2.db',
370370
'context': {'trace_id': 10, 'span_id': 19, 'is_remote': False},
371371
'parent': None,
372372
'start_time': 19000000000,
@@ -376,7 +376,7 @@ async def test_sqlalchemy_async_instrumentation(exporter: TestExporter):
376376
'logfire.msg': 'DELETE FROM auth_records WHERE auth_records.id = ?',
377377
'db.statement': 'DELETE FROM auth_records WHERE auth_records.id = ?',
378378
'db.system': 'sqlite',
379-
'db.name': 'example.db',
379+
'db.name': 'example2.db',
380380
},
381381
},
382382
]

tests/test_configure.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,6 +1036,7 @@ def test_initialize_project_not_confirming_organization(tmp_path: Path) -> None:
10361036
]
10371037

10381038

1039+
@pytest.mark.xdist_group(name='sequential')
10391040
def test_initialize_project_create_project(tmp_dir_cwd: Path, tmp_path: Path, capsys: pytest.CaptureFixture[str]):
10401041
auth_file = tmp_path / 'default.toml'
10411042
auth_file.write_text(
@@ -1160,6 +1161,7 @@ def test_initialize_project_create_project(tmp_dir_cwd: Path, tmp_path: Path, ca
11601161
}
11611162

11621163

1164+
@pytest.mark.xdist_group(name='sequential')
11631165
def test_initialize_project_create_project_default_organization(tmp_dir_cwd: Path, tmp_path: Path):
11641166
auth_file = tmp_path / 'default.toml'
11651167
auth_file.write_text(

uv.lock

Lines changed: 24 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)