Skip to content

Commit a917121

Browse files
authored
Streamline Testing with pytest-cov and pytest Defaults (#2490)
* done * update docs * try fix * update workflows * undo minor fix * resolve comments * adds back pytest-asyncio * minor fix * add branch coverage * restore pip install e. * test with coverage * fix mypy * fix coverage + docker + windows combo * fix bash command * formatter * formatter * one last fix * I lied, last fix * fix * fix retrieve chat test * fix windows paths * change cache seed * down grade openai version * fix openai mypy * better error type * fix image gen cache test * fix * experimenting * fix lmm * skip cosmos test * remove cosmos db * unused imports * handle more cosmosdb skips * fix flaky test
1 parent c94b5c6 commit a917121

17 files changed

+204
-228
lines changed

.github/workflows/build.yml

+3-4
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ jobs:
4646
python -m pip install --upgrade pip wheel
4747
pip install -e .[cosmosdb]
4848
python -c "import autogen"
49-
pip install pytest mock
49+
pip install pytest-cov>=5 mock
5050
- name: Install optional dependencies for code executors
5151
# code executors and udfs auto skip without deps, so only run for python 3.11
5252
if: matrix.python-version == '3.11'
@@ -71,12 +71,11 @@ jobs:
7171
if: matrix.python-version == '3.10'
7272
run: |
7373
pip install -e .[test,redis,websockets]
74-
coverage run -a -m pytest test --ignore=test/agentchat/contrib --skip-openai --durations=10 --durations-min=1.0
75-
coverage xml
74+
pytest test --ignore=test/agentchat/contrib --skip-openai --durations=10 --durations-min=1.0
7675
- name: Test with Cosmos DB
7776
run: |
7877
pip install -e .[test,cosmosdb]
79-
coverage run -a -m pytest test/cache/test_cosmos_db_cache.py --skip-openai --durations=10 --durations-min=1.0
78+
pytest test/cache/test_cosmos_db_cache.py --skip-openai --durations=10 --durations-min=1.0
8079
- name: Upload coverage to Codecov
8180
if: matrix.python-version == '3.10'
8281
uses: codecov/codecov-action@v3

.github/workflows/contrib-openai.yml

+96-104
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@ name: OpenAI4ContribTests
55

66
on:
77
pull_request:
8-
branches: ['main']
8+
branches: ["main"]
99
paths:
10-
- 'autogen/**'
11-
- 'test/agentchat/contrib/**'
12-
- '.github/workflows/contrib-openai.yml'
13-
- 'setup.py'
14-
permissions: {}
15-
# actions: read
10+
- "autogen/**"
11+
- "test/agentchat/contrib/**"
12+
- ".github/workflows/contrib-openai.yml"
13+
- "setup.py"
14+
permissions:
15+
{}
16+
# actions: read
1617
# checks: read
1718
# contents: read
1819
# deployments: read
@@ -55,7 +56,7 @@ jobs:
5556
python -m pip install --upgrade pip wheel
5657
pip install -e .
5758
python -c "import autogen"
58-
pip install coverage pytest-asyncio
59+
pip install pytest-cov>=5 pytest-asyncio
5960
- name: Install packages for test when needed
6061
run: |
6162
pip install docker
@@ -67,8 +68,7 @@ jobs:
6768
AZURE_OPENAI_API_BASE: ${{ secrets.AZURE_OPENAI_API_BASE }}
6869
OAI_CONFIG_LIST: ${{ secrets.OAI_CONFIG_LIST }}
6970
run: |
70-
coverage run -a -m pytest -k test_retrievechat test/agentchat/contrib/retrievechat
71-
coverage xml
71+
pytest test/agentchat/contrib/retrievechat/ test/agentchat/contrib/retrievechat
7272
- name: Upload coverage to Codecov
7373
uses: codecov/codecov-action@v3
7474
with:
@@ -98,7 +98,7 @@ jobs:
9898
python -m pip install --upgrade pip wheel
9999
pip install -e .
100100
python -c "import autogen"
101-
pip install coverage pytest-asyncio
101+
pip install pytest-cov>=5 pytest-asyncio
102102
- name: Install packages for test when needed
103103
run: |
104104
pip install docker
@@ -109,8 +109,7 @@ jobs:
109109
AZURE_OPENAI_API_BASE: ${{ secrets.AZURE_OPENAI_API_BASE }}
110110
OAI_CONFIG_LIST: ${{ secrets.OAI_CONFIG_LIST }}
111111
run: |
112-
coverage run -a -m pytest test/agentchat/contrib/test_compressible_agent.py
113-
coverage xml
112+
pytest test/agentchat/contrib/test_compressible_agent.py
114113
- name: Upload coverage to Codecov
115114
uses: codecov/codecov-action@v3
116115
with:
@@ -139,7 +138,7 @@ jobs:
139138
python -m pip install --upgrade pip wheel
140139
pip install -e .
141140
python -c "import autogen"
142-
pip install coverage pytest-asyncio
141+
pip install pytest-cov>=5 pytest-asyncio
143142
- name: Install packages for test when needed
144143
run: |
145144
pip install docker
@@ -150,8 +149,7 @@ jobs:
150149
AZURE_OPENAI_API_BASE: ${{ secrets.AZURE_OPENAI_API_BASE }}
151150
OAI_CONFIG_LIST: ${{ secrets.OAI_CONFIG_LIST }}
152151
run: |
153-
coverage run -a -m pytest test/agentchat/contrib/test_gpt_assistant.py
154-
coverage xml
152+
pytest test/agentchat/contrib/test_gpt_assistant.py
155153
- name: Upload coverage to Codecov
156154
uses: codecov/codecov-action@v3
157155
with:
@@ -180,16 +178,15 @@ jobs:
180178
python -m pip install --upgrade pip wheel
181179
pip install -e .[teachable]
182180
python -c "import autogen"
183-
pip install coverage pytest
181+
pip install pytest-cov>=5
184182
- name: Coverage
185183
env:
186184
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
187185
AZURE_OPENAI_API_KEY: ${{ secrets.AZURE_OPENAI_API_KEY }}
188186
AZURE_OPENAI_API_BASE: ${{ secrets.AZURE_OPENAI_API_BASE }}
189187
OAI_CONFIG_LIST: ${{ secrets.OAI_CONFIG_LIST }}
190188
run: |
191-
coverage run -a -m pytest test/agentchat/contrib/capabilities/test_teachable_agent.py
192-
coverage xml
189+
pytest test/agentchat/contrib/capabilities/test_teachable_agent.py
193190
- name: Upload coverage to Codecov
194191
uses: codecov/codecov-action@v3
195192
with:
@@ -198,8 +195,8 @@ jobs:
198195
AgentBuilder:
199196
strategy:
200197
matrix:
201-
os: [ ubuntu-latest ]
202-
python-version: [ "3.11" ]
198+
os: [ubuntu-latest]
199+
python-version: ["3.11"]
203200
runs-on: ${{ matrix.os }}
204201
environment: openai1
205202
steps:
@@ -218,7 +215,7 @@ jobs:
218215
python -m pip install --upgrade pip wheel
219216
pip install -e .
220217
python -c "import autogen"
221-
pip install coverage pytest-asyncio
218+
pip install pytest-cov>=5 pytest-asyncio
222219
- name: Install packages for test when needed
223220
run: |
224221
pip install -e .[autobuild]
@@ -229,8 +226,7 @@ jobs:
229226
AZURE_OPENAI_API_BASE: ${{ secrets.AZURE_OPENAI_API_BASE }}
230227
OAI_CONFIG_LIST: ${{ secrets.OAI_CONFIG_LIST }}
231228
run: |
232-
coverage run -a -m pytest test/agentchat/contrib/test_agent_builder.py
233-
coverage xml
229+
pytest test/agentchat/contrib/test_agent_builder.py
234230
- name: Upload coverage to Codecov
235231
uses: codecov/codecov-action@v3
236232
with:
@@ -259,7 +255,7 @@ jobs:
259255
python -m pip install --upgrade pip wheel
260256
pip install -e .[websurfer]
261257
python -c "import autogen"
262-
pip install coverage pytest
258+
pip install pytest-cov>=5
263259
- name: Coverage
264260
env:
265261
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
@@ -268,93 +264,90 @@ jobs:
268264
OAI_CONFIG_LIST: ${{ secrets.OAI_CONFIG_LIST }}
269265
BING_API_KEY: ${{ secrets.BING_API_KEY }}
270266
run: |
271-
coverage run -a -m pytest test/agentchat/contrib/test_web_surfer.py
272-
coverage xml
267+
pytest test/agentchat/contrib/test_web_surfer.py
273268
- name: Upload coverage to Codecov
274269
uses: codecov/codecov-action@v3
275270
with:
276271
file: ./coverage.xml
277272
flags: unittests
278273
ContextHandling:
279-
strategy:
280-
matrix:
281-
os: [ubuntu-latest]
282-
python-version: ["3.11"]
283-
runs-on: ${{ matrix.os }}
284-
environment: openai1
285-
steps:
286-
# checkout to pr branch
287-
- name: Checkout
288-
uses: actions/checkout@v4
289-
with:
290-
ref: ${{ github.event.pull_request.head.sha }}
291-
- name: Set up Python ${{ matrix.python-version }}
292-
uses: actions/setup-python@v5
293-
with:
294-
python-version: ${{ matrix.python-version }}
295-
- name: Install packages and dependencies
296-
run: |
297-
docker --version
298-
python -m pip install --upgrade pip wheel
299-
pip install -e .
300-
python -c "import autogen"
301-
pip install coverage pytest
302-
- name: Coverage
303-
env:
304-
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
305-
AZURE_OPENAI_API_KEY: ${{ secrets.AZURE_OPENAI_API_KEY }}
306-
AZURE_OPENAI_API_BASE: ${{ secrets.AZURE_OPENAI_API_BASE }}
307-
OAI_CONFIG_LIST: ${{ secrets.OAI_CONFIG_LIST }}
308-
BING_API_KEY: ${{ secrets.BING_API_KEY }}
309-
run: |
310-
coverage run -a -m pytest test/agentchat/contrib/capabilities/test_context_handling.py
311-
coverage xml
312-
- name: Upload coverage to Codecov
313-
uses: codecov/codecov-action@v3
314-
with:
315-
file: ./coverage.xml
316-
flags: unittests
274+
strategy:
275+
matrix:
276+
os: [ubuntu-latest]
277+
python-version: ["3.11"]
278+
runs-on: ${{ matrix.os }}
279+
environment: openai1
280+
steps:
281+
# checkout to pr branch
282+
- name: Checkout
283+
uses: actions/checkout@v4
284+
with:
285+
ref: ${{ github.event.pull_request.head.sha }}
286+
- name: Set up Python ${{ matrix.python-version }}
287+
uses: actions/setup-python@v5
288+
with:
289+
python-version: ${{ matrix.python-version }}
290+
- name: Install packages and dependencies
291+
run: |
292+
docker --version
293+
python -m pip install --upgrade pip wheel
294+
pip install -e .
295+
python -c "import autogen"
296+
pip install pytest-cov>=5
297+
- name: Coverage
298+
env:
299+
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
300+
AZURE_OPENAI_API_KEY: ${{ secrets.AZURE_OPENAI_API_KEY }}
301+
AZURE_OPENAI_API_BASE: ${{ secrets.AZURE_OPENAI_API_BASE }}
302+
OAI_CONFIG_LIST: ${{ secrets.OAI_CONFIG_LIST }}
303+
BING_API_KEY: ${{ secrets.BING_API_KEY }}
304+
run: |
305+
pytest test/agentchat/contrib/capabilities/test_context_handling.py
306+
- name: Upload coverage to Codecov
307+
uses: codecov/codecov-action@v3
308+
with:
309+
file: ./coverage.xml
310+
flags: unittests
317311
ImageGen:
318-
strategy:
319-
matrix:
320-
os: [ubuntu-latest]
321-
python-version: ["3.12"]
322-
runs-on: ${{ matrix.os }}
323-
environment: openai1
324-
steps:
325-
# checkout to pr branch
326-
- name: Checkout
327-
uses: actions/checkout@v4
328-
with:
329-
ref: ${{ github.event.pull_request.head.sha }}
330-
- name: Set up Python ${{ matrix.python-version }}
331-
uses: actions/setup-python@v5
332-
with:
333-
python-version: ${{ matrix.python-version }}
334-
- name: Install packages and dependencies
335-
run: |
336-
docker --version
337-
python -m pip install --upgrade pip wheel
338-
pip install -e .[lmm]
339-
python -c "import autogen"
340-
pip install coverage pytest
341-
- name: Coverage
342-
env:
343-
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
344-
run: |
345-
coverage run -a -m pytest test/agentchat/contrib/capabilities/test_image_generation_capability.py
346-
coverage xml
347-
- name: Upload coverage to Codecov
348-
uses: codecov/codecov-action@v3
349-
with:
350-
file: ./coverage.xml
351-
flags: unittests
312+
strategy:
313+
matrix:
314+
os: [ubuntu-latest]
315+
python-version: ["3.12"]
316+
runs-on: ${{ matrix.os }}
317+
environment: openai1
318+
steps:
319+
# checkout to pr branch
320+
- name: Checkout
321+
uses: actions/checkout@v4
322+
with:
323+
ref: ${{ github.event.pull_request.head.sha }}
324+
- name: Set up Python ${{ matrix.python-version }}
325+
uses: actions/setup-python@v5
326+
with:
327+
python-version: ${{ matrix.python-version }}
328+
- name: Install packages and dependencies
329+
run: |
330+
docker --version
331+
python -m pip install --upgrade pip wheel
332+
pip install -e .[lmm]
333+
python -c "import autogen"
334+
pip install pytest-cov>=5
335+
- name: Coverage
336+
env:
337+
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
338+
run: |
339+
pytest test/agentchat/contrib/capabilities/test_image_generation_capability.py
340+
- name: Upload coverage to Codecov
341+
uses: codecov/codecov-action@v3
342+
with:
343+
file: ./coverage.xml
344+
flags: unittests
352345

353346
AgentOptimizer:
354347
strategy:
355348
matrix:
356-
os: [ ubuntu-latest ]
357-
python-version: [ "3.11" ]
349+
os: [ubuntu-latest]
350+
python-version: ["3.11"]
358351
runs-on: ${{ matrix.os }}
359352
environment: openai1
360353
steps:
@@ -373,16 +366,15 @@ jobs:
373366
python -m pip install --upgrade pip wheel
374367
pip install -e .
375368
python -c "import autogen"
376-
pip install coverage pytest
369+
pip install pytest-cov>=5
377370
- name: Coverage
378371
env:
379372
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
380373
AZURE_OPENAI_API_KEY: ${{ secrets.AZURE_OPENAI_API_KEY }}
381374
AZURE_OPENAI_API_BASE: ${{ secrets.AZURE_OPENAI_API_BASE }}
382375
OAI_CONFIG_LIST: ${{ secrets.OAI_CONFIG_LIST }}
383376
run: |
384-
coverage run -a -m pytest test/agentchat/contrib/test_agent_optimizer.py
385-
coverage xml
377+
pytest test/agentchat/contrib/test_agent_optimizer.py
386378
- name: Upload coverage to Codecov
387379
uses: codecov/codecov-action@v3
388380
with:

0 commit comments

Comments
 (0)