Skip to content

Commit

Permalink
estabilish test structure: unit & integration
Browse files Browse the repository at this point in the history
  • Loading branch information
xianglong-hu-cf committed Dec 8, 2024
1 parent 719781c commit 0766f4e
Show file tree
Hide file tree
Showing 123 changed files with 39 additions and 7 deletions.
29 changes: 26 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ Ensuring excellent documentation and thorough testing is absolutely crucial. Her
- Update any affected example console scripts in the `examples` directory, Gradio demos in the `apps` directory, and documentation in the `docs` directory.
- Update unit tests when relevant.
- If you add a feature:
- Include unit tests in the `test` directory.
- Include unit tests in the `test/unit` directory, which can be run locally.
- Include integration tests in the `test/integration` directory, which needs web requests like OpenAI.
- Add a demo script in the `examples` directory.

We're a small team focused on building great things. If you have something in mind that you'd like to add or modify, opening a pull request is the ideal way to catch our attention. 🚀
Expand Down Expand Up @@ -240,7 +241,7 @@ pre-commit install
# Run camel's pre-commit before push
pre-commit run --all-files

# Run camel's unit tests
# Run all tests, expect most of them would fail
pytest test

# Exit the virtual environment
Expand Down Expand Up @@ -298,7 +299,7 @@ pytest --cov --cov-report=html

The coverage report will be generated at `htmlcov/index.html`.

### Tests 🧪
## Tests 🧪

Unit tests cover modular logic that doesn't require calls to outside APIs. Currently, the test setup requires an OpenAI API key to test the framework, making them resemble integration tests.

Expand All @@ -312,6 +313,11 @@ To quickly run only local isolated unit and integration tests:
```bash
pytest --fast-test-mode .
```
this is defined in `conftest.py`.
which is equivalent to
```bash
pytest -m "not optional and not model_backend"
```

If you're developing with VSCode, make sure to create a `.env` file in the repository root and include your OpenAI API key:

Expand All @@ -320,6 +326,23 @@ OPENAI_API_KEY=sk-XXXXXXXX
OPENAI_API_BASE_URL=https://XXXXXXXX (Should you utilize an OpenAI proxy service, kindly specify this)
```

### Unit & Integration
As integration tests require token and third-party setup, it is costly to run locally. Ideally, developers should run unit test locally and run integration tests in github/CI/CD.

The recommended way to run the integration tests is to create a draft PR and all tests will be run on github. It is not recommended to run integration tests locally.

To run a single unit test locally, use
```bash
pytest ./test/unit/agents/test_agent_base.py
```

A developer is expected to add unit tests under `test/unit` and integration tests under `test/integration`.

Note: We have some tech debt that unit tests and integration tests are not decoupled. So some tests under integration might actually be unit tests.

### Use Decorator
Ideally you should use pytest decorators for all the tests, check pytest.ini for marker definitions.

## Documentation 📚

### Contribute to Documentation 📝
Expand Down
9 changes: 9 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[pytest]
markers =
unit: marks tests as unit tests
integration: marks tests as integration tests
model_backend: model backend
very_slow: very slow tests
optional: optional tests


File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ def from_bytes(cls, file: BytesIO, filename: str) -> "FakeFile":

# Define paths to test resources
UNIT_TESTS_ROOT = Path(__file__).parent.resolve()
TESTS_ROOT = UNIT_TESTS_ROOT.parent.resolve()
PROJECT_ROOT = TESTS_ROOT.parent.resolve()
RESOURCE_ROOT = PROJECT_ROOT / "test"
SAMPLE_ROOT = RESOURCE_ROOT / "data_samples"
INT_TESTS_ROOT = UNIT_TESTS_ROOT.parent.resolve()
TEST_ROOT = INT_TESTS_ROOT.parent.resolve()
RESOURCE_ROOT = TEST_ROOT
SAMPLE_ROOT = RESOURCE_ROOT / "integration" / "data_samples"


# Test functions for each file type
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 0766f4e

Please sign in to comment.