|
1 | 1 | # Running Unit Tests for Agent365-Python SDK |
2 | 2 |
|
3 | | -## Quick Start |
| 3 | +This guide covers setting up and running tests in Visual Studio Code. |
4 | 4 |
|
5 | | -```bash |
6 | | -# Install dependencies |
7 | | -uv pip install -e libraries/microsoft-agents-a365-runtime |
8 | | -uv pip install pytest pytest-cov pytest-asyncio |
| 5 | +--- |
9 | 6 |
|
10 | | -# Run all tests |
11 | | -python -m pytest tests/ |
| 7 | +## Prerequisites |
12 | 8 |
|
13 | | -# Run with coverage |
14 | | -python -m pytest tests/runtime/ --cov=microsoft_agents_a365.runtime --cov-report=html |
15 | | -``` |
| 9 | +- **Python 3.11+** installed |
| 10 | +- **Visual Studio Code** with Python extension |
| 11 | +- **Git** repository cloned locally |
16 | 12 |
|
17 | 13 | --- |
18 | 14 |
|
19 | | -## Current Test Status |
| 15 | +## Test Structure |
20 | 16 |
|
21 | | -| Module | Tests | Status | |
22 | | -|--------|-------|--------| |
23 | | -| Runtime | 53 | ✅ Complete | |
24 | | -| Observability | ~20 | ⚠️ Partial | |
25 | | -| Tooling | 0 | ❌ Not Started | |
26 | | -| Notifications | 0 | ❌ Not Started | |
| 17 | +> **Note:** This structure will be updated as new tests are added. |
27 | 18 |
|
28 | | -**Coverage Target:** 80%+ | See [TEST_PLAN.md](TEST_PLAN.md) for roadmap |
| 19 | +```plaintext |
| 20 | +tests/ |
| 21 | +├── runtime/ # Runtime tests |
| 22 | +├── observability/ # Observability tests |
| 23 | +├── tooling/ # Tooling tests |
| 24 | +└── notifications/ # Notifications tests |
| 25 | +``` |
29 | 26 |
|
30 | 27 | --- |
31 | 28 |
|
32 | | -## Installation |
| 29 | +## Initial Setup |
33 | 30 |
|
34 | | -```bash |
35 | | -# Runtime module only |
36 | | -uv pip install -e libraries/microsoft-agents-a365-runtime |
37 | | -uv pip install pytest pytest-cov pytest-asyncio |
38 | | - |
39 | | -# All modules |
40 | | -uv pip install -e libraries/microsoft-agents-a365-observability-core |
41 | | -uv pip install -e libraries/microsoft-agents-a365-tooling |
42 | | -uv pip install -e libraries/microsoft-agents-a365-notifications |
43 | | -``` |
| 31 | +### 1. Configure Python Environment |
44 | 32 |
|
45 | | ---- |
| 33 | +1. Press `Ctrl+Shift+P` |
| 34 | +2. Type "Python: Select Interpreter" |
| 35 | +3. Choose your Python 3.11+ interpreter |
46 | 36 |
|
47 | | -## Running Tests |
| 37 | +### 2. Install Dependencies |
48 | 38 |
|
49 | | -```bash |
50 | | -# All tests |
51 | | -python -m pytest tests/ |
| 39 | +```powershell |
| 40 | +# Install test dependencies |
| 41 | +uv pip install pytest pytest-asyncio pytest-mock pytest-cov pytest-html |
52 | 42 |
|
53 | | -# Specific module |
54 | | -python -m pytest tests/runtime/ |
| 43 | +# Install workspace packages |
| 44 | +uv pip install -e . |
| 45 | +``` |
55 | 46 |
|
56 | | -# Specific file |
57 | | -python -m pytest tests/runtime/test_environment_utils.py |
| 47 | +--- |
58 | 48 |
|
59 | | -# Specific test |
60 | | -python -m pytest tests/runtime/test_environment_utils.py::TestEnvironmentUtils::test_constants |
| 49 | +## Running Tests in VS Code |
61 | 50 |
|
62 | | -# With verbose output |
63 | | -python -m pytest tests/runtime/ -v |
| 51 | +### Test Explorer |
64 | 52 |
|
65 | | -# Stop on first failure |
66 | | -python -m pytest tests/runtime/ -x |
| 53 | +1. Click the beaker icon in the Activity Bar or press `Ctrl+Shift+P` → "Test: Focus on Test Explorer View" |
| 54 | +2. Click the play button to run tests (all/folder/file/individual) |
| 55 | +3. Right-click → "Debug Test" to debug with breakpoints |
67 | 56 |
|
68 | | -# Pattern matching |
69 | | -python -m pytest tests/runtime/ -k "environment" |
| 57 | +### Command Palette |
70 | 58 |
|
71 | | -# Re-run failed tests only |
72 | | -python -m pytest --lf |
73 | | -``` |
| 59 | +- `Test: Run All Tests` |
| 60 | +- `Test: Run Tests in Current File` |
| 61 | +- `Test: Debug Tests in Current File` |
74 | 62 |
|
75 | 63 | --- |
76 | 64 |
|
77 | | -## Coverage Reports |
| 65 | +## Running Tests from Command Line |
78 | 66 |
|
79 | | -```bash |
80 | | -# Terminal output |
81 | | -python -m pytest tests/runtime/ --cov=microsoft_agents_a365.runtime --cov-report=term-missing |
| 67 | +```powershell |
| 68 | +# Run all tests |
| 69 | +python -m pytest tests/ |
82 | 70 |
|
83 | | -# HTML report (opens htmlcov/index.html) |
84 | | -python -m pytest tests/runtime/ --cov=microsoft_agents_a365.runtime --cov-report=html |
| 71 | +# Run specific module/file |
| 72 | +python -m pytest tests/runtime/ |
| 73 | +python -m pytest tests/runtime/test_environment_utils.py |
85 | 74 |
|
86 | | -# XML report (for CI/CD tools) |
87 | | -python -m pytest tests/runtime/ --cov=microsoft_agents_a365.runtime --cov-report=xml |
| 75 | +# Run with options |
| 76 | +python -m pytest tests/ -v # Verbose |
| 77 | +python -m pytest tests/ -x # Stop on first failure |
| 78 | +python -m pytest tests/ -k "environment" # Pattern matching |
| 79 | +python -m pytest --lf # Re-run failed tests |
88 | 80 | ``` |
89 | 81 |
|
90 | 82 | --- |
91 | 83 |
|
92 | | -## Advanced Options |
| 84 | +## Generating Reports |
93 | 85 |
|
94 | | -```bash |
95 | | -# Parallel execution |
96 | | -uv pip install pytest-xdist |
97 | | -python -m pytest tests/runtime/ -n auto |
| 86 | +### HTML Reports |
98 | 87 |
|
99 | | -# JUnit XML report |
100 | | -python -m pytest tests/runtime/ --junitxml=test-results.xml |
101 | | -``` |
102 | | - |
103 | | ---- |
| 88 | +```powershell |
| 89 | +# Coverage report |
| 90 | +python -m pytest tests/ --cov=libraries --cov-report=html |
| 91 | +Invoke-Item htmlcov\index.html |
104 | 92 |
|
105 | | -## Understanding Output |
| 93 | +# Test report |
| 94 | +python -m pytest tests/ --html=test-report.html --self-contained-html |
| 95 | +Invoke-Item test-report.html |
106 | 96 |
|
| 97 | +# Combined |
| 98 | +python -m pytest tests/ --cov=libraries --cov-report=html --html=test-report.html --self-contained-html -v |
107 | 99 | ``` |
108 | | -tests/runtime/test_environment_utils.py::TestEnvironmentUtils::test_constants PASSED [ 1%] |
109 | | -=================================== 53 passed in 0.18s =================================== |
110 | | -``` |
111 | 100 |
|
112 | | -| Status | Description | |
113 | | -|--------|-------------| |
114 | | -| **PASSED** | Test passed successfully | |
115 | | -| **FAILED** | Test failed (shows error details) | |
116 | | -| **SKIPPED** | Test skipped | |
117 | | -| **ERROR** | Error during collection/setup | |
| 101 | +### CI/CD Reports |
| 102 | + |
| 103 | +```powershell |
| 104 | +# XML reports for CI/CD pipelines |
| 105 | +python -m pytest tests/ --cov=libraries --cov-report=xml --junitxml=test-results.xml |
| 106 | +``` |
118 | 107 |
|
119 | 108 | --- |
120 | 109 |
|
121 | 110 | ## Troubleshooting |
122 | 111 |
|
| 112 | +### Common Issues |
| 113 | + |
123 | 114 | | Issue | Solution | |
124 | 115 | |-------|----------| |
125 | | -| `ModuleNotFoundError` | `uv pip install -e libraries/microsoft-agents-a365-runtime` | |
126 | | -| `pytest: command not found` | `uv pip install pytest` | |
127 | | -| `ERROR: unrecognized arguments: --cov` | `uv pip install pytest-cov` | |
| 116 | +| **Test loading failed** | Clean pyproject.toml, reinstall packages, restart VS Code | |
| 117 | +| **ImportError: No module named 'pytest'** | `uv pip install pytest pytest-asyncio pytest-mock` | |
| 118 | +| **ImportError: No module named 'microsoft_agents_a365'** | `uv pip install -e .` | |
| 119 | +| **Tests not discovered** | Refresh Test Explorer or restart VS Code | |
128 | 120 |
|
129 | | ---- |
| 121 | +### Fix Steps |
130 | 122 |
|
131 | | -## Test Structure |
| 123 | +If tests fail to discover or import errors occur: |
132 | 124 |
|
| 125 | +**1. Clean pyproject.toml** |
| 126 | + |
| 127 | +```powershell |
| 128 | +$content = Get-Content "pyproject.toml" -Raw |
| 129 | +$fixed = $content -replace "`r`n", "`n" |
| 130 | +$fixed | Set-Content "pyproject.toml" -NoNewline |
133 | 131 | ``` |
134 | | -tests/ |
135 | | -├── README.md # Overview |
136 | | -├── RUNNING_TESTS.md # This file |
137 | | -├── TEST_PLAN.md # Test strategy |
138 | | -└── runtime/ |
139 | | - ├── test_environment_utils.py # 16 tests |
140 | | - ├── test_version_utils.py # 12 tests |
141 | | - ├── test_utility.py # 13 tests |
142 | | - └── test_power_platform_api_discovery.py # 12 tests |
| 132 | + |
| 133 | +**2. Reinstall packages** |
| 134 | + |
| 135 | +```powershell |
| 136 | +uv pip install -e . |
143 | 137 | ``` |
| 138 | + |
| 139 | +**3. Restart VS Code** |
| 140 | + |
| 141 | +- Close completely and reopen |
| 142 | +- Wait for Python extension to reload |
| 143 | +- Refresh Test Explorer |
0 commit comments