Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/bindings_python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:
env:
OPENDAL_MEMORY_TEST: on
run: |
pytest -vk TestMemory
pytest --service_type=service_memory -v ./tests

linux:
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/service_test_memory.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,6 @@ jobs:
- name: Test
shell: bash
working-directory: bindings/python
run: pytest -vk TestMemory
run: pytest --service_type=service_memory -v ./tests
env:
OPENDAL_MEMORY_TEST: on
2 changes: 1 addition & 1 deletion .github/workflows/service_test_s3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ jobs:
- name: Test
shell: bash
working-directory: bindings/python
run: pytest -vk TestS3
run: pytest --service_type=service_s3 -v ./tests
env:
OPENDAL_S3_TEST: on
OPENDAL_S3_BUCKET: test
Expand Down
2 changes: 1 addition & 1 deletion bindings/python/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ OpenDAL adopts `pytest` for behavior tests:

```shell
maturin develop -E test
OPENDAL_MEMORY_TEST=on pytest -vk TestMemory
OPENDAL_MEMORY_TEST=on pytest --service_type=service_memory -v ./tests
```

## Docs
Expand Down
2 changes: 1 addition & 1 deletion bindings/python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ Run some tests:

```shell
maturin develop -E test
OPENDAL_MEMORY_TEST=on pytest -vk TestMemory
OPENDAL_MEMORY_TEST=on pytest --service_type=service_memory -v ./tests
```

Build API docs:
Expand Down
58 changes: 56 additions & 2 deletions bindings/python/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,63 @@
# specific language governing permissions and limitations
# under the License.

from dotenv import load_dotenv
# from dotenv import load_dotenv
import pytest
import os

import opendal
import pytest


load_dotenv()
# load_dotenv()
pytest_plugins = ("pytest_asyncio",)

SERVICE_TYPE_INDEX = {
"service_memory": "memory",
"service_s3": "s3",
"service_fs": "fs",
}


def pytest_addoption(parser):
parser.addoption("--service_type", action="store", default="")


def setup_config(service_name):
prefix = f"opendal_{service_name}_"
config = {}
for key in os.environ.keys():
if key.lower().startswith(prefix):
config[key[len(prefix) :].lower()] = os.environ.get(key)

# Check if current test be enabled.
test_flag = config.get("test", "")
if test_flag != "on" and test_flag != "true":
raise ValueError(f"Service {service_name} test is not enabled.")
return config


def operator(service_name, setup_config):
return opendal.Operator(service_name, **setup_config)


def async_operator(service_name, setup_config):
return opendal.AsyncOperator(service_name, **setup_config)


def pytest_generate_tests(metafunc):
service_types = metafunc.config.getoption("service_type").split(",")
fixtures = []
for service_type in service_types:
service_name = SERVICE_TYPE_INDEX.get(service_type)
if service_name is None:
raise ValueError(f"Service {service_type} is not supported.")
config = setup_config(service_name)
fixtures.append(
(
service_name,
operator(service_name, config),
async_operator(service_name, config),
)
)
metafunc.parametrize("service_name, operator, async_operator", fixtures)
Loading