test: add scripts for running tests on api module both locally and CI jobs (#3497)

This commit is contained in:
Bowen Liang
2024-04-18 13:43:15 +08:00
committed by GitHub
parent ed861ff782
commit d463b82aba
8 changed files with 66 additions and 5 deletions

View File

@@ -55,3 +55,16 @@
9. If you need to debug local async processing, please start the worker service by running
`celery -A app.celery worker -P gevent -c 1 --loglevel INFO -Q dataset,generation,mail`.
The started celery app handles the async tasks, e.g. dataset importing and documents indexing.
## Testing
1. Install dependencies for both the backend and the test environment
```bash
pip install -r requirements.txt -r requirements-dev.txt
```
2. Run the tests locally with mocked system environment variables in `tool.pytest_env` section in `pyproject.toml`
```bash
dev/pytest/pytest_all_tests.sh
```

View File

@@ -25,3 +25,23 @@ ignore = [
"UP007", # non-pep604-annotation
"UP032", # f-string
]
[tool.pytest_env]
OPENAI_API_KEY = "sk-IamNotARealKeyJustForMockTestKawaiiiiiiiiii"
AZURE_OPENAI_API_BASE = "https://difyai-openai.openai.azure.com"
AZURE_OPENAI_API_KEY = "xxxxb1707exxxxxxxxxxaaxxxxxf94"
ANTHROPIC_API_KEY = "sk-ant-api11-IamNotARealKeyJustForMockTestKawaiiiiiiiiii-NotBaka-ASkksz"
CHATGLM_API_BASE = "http://a.abc.com:11451"
XINFERENCE_SERVER_URL = "http://a.abc.com:11451"
XINFERENCE_GENERATION_MODEL_UID = "generate"
XINFERENCE_CHAT_MODEL_UID = "chat"
XINFERENCE_EMBEDDINGS_MODEL_UID = "embedding"
XINFERENCE_RERANK_MODEL_UID = "rerank"
GOOGLE_API_KEY = "abcdefghijklmnopqrstuvwxyz"
HUGGINGFACE_API_KEY = "hf-awuwuwuwuwuwuwuwuwuwuwuwuwuwuwuwuwu"
HUGGINGFACE_TEXT_GEN_ENDPOINT_URL = "a"
HUGGINGFACE_TEXT2TEXT_GEN_ENDPOINT_URL = "b"
HUGGINGFACE_EMBEDDINGS_ENDPOINT_URL = "c"
MOCK_SWITCH = "true"
CODE_MAX_STRING_LENGTH = "80000"

View File

@@ -1,4 +1,5 @@
coverage~=7.2.4
pytest~=7.3.1
pytest-mock~=3.11.1
pytest~=8.1.1
pytest-benchmark~=4.0.0
pytest-env~=1.1.3
pytest-mock~=3.14.0