Skip to content

Commit

Permalink
Test collections unique per openapi test module (qdrant#5384)
Browse files Browse the repository at this point in the history
Collection name under test is equal to the test module name, without `.py` suffix.

* Helps by debugging/tracing failed tests and find relevant logs lines in qdrant log files
* Opens up a possibility to run tests in parallel, given that there are no data sharing
  between test modules

Change details:
* defined module scoped `collection_name` fixture in `conftest.py`
* removed `collection_name` module variable
* each test signature modified to declare the dependency to `collection_name` fixture
* `@pytest.mark.parametrize` migrated to `@pytest-cases.parametrize` in cases when
  `collection_name` was used as the value
  • Loading branch information
pedjak authored and timvisee committed Nov 8, 2024
1 parent 68e88a5 commit 96a5a2b
Show file tree
Hide file tree
Showing 64 changed files with 523 additions and 523 deletions.
5 changes: 5 additions & 0 deletions tests/openapi/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,8 @@ def log_request(self, *args, **kwargs):
yield (tmpdir, f"http://{HTTP_SERVER_HOST}:{httpd.server_address[1]}")
httpd.shutdown()
thread.join()


@pytest.fixture(scope='module', autouse=True)
def collection_name(request):
return request.node.name.removesuffix(".py")
20 changes: 9 additions & 11 deletions tests/openapi/test_alias.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,16 @@
from .helpers.collection_setup import basic_collection_setup, drop_collection
from .helpers.helpers import request_with_validation

collection_name = 'test_collection_alias'


@pytest.fixture(autouse=True)
def setup(on_disk_vectors):
def setup(on_disk_vectors, collection_name):
basic_collection_setup(collection_name=collection_name, on_disk_vectors=on_disk_vectors)
yield
drop_collection(collection_name=collection_name)
drop_collection(collection_name=f'{collection_name}_2')


def test_cant_create_alias_if_collection_exists(on_disk_vectors):
def test_cant_create_alias_if_collection_exists(on_disk_vectors, collection_name):
second_collection_name = f'{collection_name}_2'

basic_collection_setup(collection_name=second_collection_name, on_disk_vectors=on_disk_vectors)
Expand All @@ -37,7 +35,7 @@ def test_cant_create_alias_if_collection_exists(on_disk_vectors):
assert response.status_code == 409


def test_cant_create_collection_if_alias_exists(on_disk_vectors):
def test_cant_create_collection_if_alias_exists(on_disk_vectors, collection_name):
second_collection_name = f'{collection_name}_3'

response = request_with_validation(
Expand Down Expand Up @@ -87,15 +85,15 @@ def test_cant_create_collection_if_alias_exists(on_disk_vectors):
assert response.status_code == 400


def test_alias_operations():
def test_alias_operations(collection_name):
response = request_with_validation(
api='/collections/aliases',
method="POST",
body={
"actions": [
{
"create_alias": {
"alias_name": "test_alias",
"alias_name": "alias",
"collection_name": collection_name
}
}
Expand All @@ -111,7 +109,7 @@ def test_alias_operations():
assert response.ok
assert len(response.json()['result']['aliases']) == 1
first_alias = response.json()['result']['aliases'][0]
assert first_alias['alias_name'] == 'test_alias'
assert first_alias['alias_name'] == 'alias'
assert first_alias['collection_name'] == collection_name

response = request_with_validation(
Expand All @@ -122,7 +120,7 @@ def test_alias_operations():
assert response.ok
assert len(response.json()['result']['aliases']) == 1
first_alias = response.json()['result']['aliases'][0]
assert first_alias['alias_name'] == 'test_alias'
assert first_alias['alias_name'] == 'alias'
assert first_alias['collection_name'] == collection_name

response = request_with_validation(
Expand Down Expand Up @@ -156,7 +154,7 @@ def test_alias_operations():
"actions": [
{
"delete_alias": {
"alias_name": "test_alias"
"alias_name": "alias"
}
}
]
Expand All @@ -174,7 +172,7 @@ def test_alias_operations():
response = request_with_validation(
api='/collections/{collection_name}/points/search',
method="POST",
path_params={'collection_name': "test_alias"},
path_params={'collection_name': "alias"},
body={
"vector": [0.2, 0.1, 0.9, 0.7],
"limit": 3
Expand Down
22 changes: 10 additions & 12 deletions tests/openapi/test_basic_retrieve_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,15 @@
from .helpers.collection_setup import basic_collection_setup, drop_collection
from .helpers.helpers import request_with_validation

collection_name = 'test_collection'


@pytest.fixture(autouse=True, scope="module")
def setup(on_disk_vectors):
def setup(on_disk_vectors, collection_name):
basic_collection_setup(collection_name=collection_name, on_disk_vectors=on_disk_vectors)
yield
drop_collection(collection_name=collection_name)


def test_points_retrieve():
def test_points_retrieve(collection_name):
response = request_with_validation(
api='/collections/{collection_name}/points/{id}',
method="GET",
Expand Down Expand Up @@ -85,7 +83,7 @@ def test_points_retrieve():
assert len(response.json()['result']['points']) == 2


def test_exclude_payload():
def test_exclude_payload(collection_name):
response = request_with_validation(
api='/collections/{collection_name}/points/search',
method="POST",
Expand Down Expand Up @@ -114,7 +112,7 @@ def test_exclude_payload():
assert 'city' not in result['payload']


def test_batch_search():
def test_batch_search(collection_name):
response = request_with_validation(
api="/collections/{collection_name}/points/search/batch",
method="POST",
Expand Down Expand Up @@ -150,7 +148,7 @@ def test_batch_search():
assert len(response.json()["result"]) == 0


def test_is_empty_condition():
def test_is_empty_condition(collection_name):
response = request_with_validation(
api='/collections/{collection_name}/points/search',
method="POST",
Expand Down Expand Up @@ -183,7 +181,7 @@ def test_is_empty_condition():
assert 8 in ids


def test_is_null_condition():
def test_is_null_condition(collection_name):
response = request_with_validation(
api='/collections/{collection_name}/points/search',
method="POST",
Expand Down Expand Up @@ -248,7 +246,7 @@ def must_not_is_null(field: str):
must_not_is_null("city[]")


def test_recommendation():
def test_recommendation(collection_name):
response = request_with_validation(
api='/collections/{collection_name}/points/recommend',
method="POST",
Expand All @@ -266,7 +264,7 @@ def test_recommendation():
assert response.ok


def test_query_single_condition():
def test_query_single_condition(collection_name):
response = request_with_validation(
api='/collections/{collection_name}/points/search',
method="POST",
Expand All @@ -289,7 +287,7 @@ def test_query_single_condition():
assert len(response.json()['result']) == 2


def test_query_nested():
def test_query_nested(collection_name):
response = request_with_validation(
api='/collections/{collection_name}/points',
method="PUT",
Expand Down Expand Up @@ -336,7 +334,7 @@ def test_query_nested():
assert len(response.json()['result']['points']) == 1


def test_with_vectors_alias_of_with_vector():
def test_with_vectors_alias_of_with_vector(collection_name):
database_id = "8594ff5d-265f-adfh-a9f5-b3b4b9665506"
vector = [0.15, 0.31, 0.76, 0.74]

Expand Down
16 changes: 7 additions & 9 deletions tests/openapi/test_basic_retrieve_multivec_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,15 @@
from .helpers.collection_setup import drop_collection, multivec_collection_setup
from .helpers.helpers import request_with_validation

collection_name = 'test_collection'


@pytest.fixture(autouse=True, scope="module")
def setup(on_disk_vectors):
def setup(on_disk_vectors, collection_name):
multivec_collection_setup(collection_name=collection_name, on_disk_vectors=on_disk_vectors)
yield
drop_collection(collection_name=collection_name)


def test_points_retrieve():
def test_points_retrieve(collection_name):
response = request_with_validation(
api='/collections/{collection_name}/points/{id}',
method="GET",
Expand Down Expand Up @@ -122,7 +120,7 @@ def test_points_retrieve():
assert len(point['vector']['sparse-image']) == 2


def test_retrieve_invalid_vector():
def test_retrieve_invalid_vector(collection_name):
# Retrieve nonexistent vector name
response = request_with_validation(
api='/collections/{collection_name}/points',
Expand All @@ -141,7 +139,7 @@ def test_retrieve_invalid_vector():
assert error == "Wrong input: Not existing vector name error: i_do_no_exist"


def test_exclude_payload():
def test_exclude_payload(collection_name):
response = request_with_validation(
api='/collections/{collection_name}/points/search',
method="POST",
Expand Down Expand Up @@ -170,7 +168,7 @@ def test_exclude_payload():
assert 'city' not in result['payload']


def test_is_empty_condition():
def test_is_empty_condition(collection_name):
response = request_with_validation(
api='/collections/{collection_name}/points/search',
method="POST",
Expand All @@ -197,7 +195,7 @@ def test_is_empty_condition():
assert response.ok


def test_recommendation():
def test_recommendation(collection_name):
response = request_with_validation(
api='/collections/{collection_name}/points/recommend',
method="POST",
Expand All @@ -216,7 +214,7 @@ def test_recommendation():
assert response.ok


def test_query_nested():
def test_query_nested(collection_name):
response = request_with_validation(
api='/collections/{collection_name}/points',
method="PUT",
Expand Down
38 changes: 18 additions & 20 deletions tests/openapi/test_batch_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,16 @@
from .helpers.collection_setup import basic_collection_setup, drop_collection
from .helpers.helpers import request_with_validation

collection_name = 'test_collection_batch_update'


@pytest.fixture(autouse=True)
def setup(on_disk_vectors, on_disk_payload):
def setup(on_disk_vectors, on_disk_payload, collection_name):
basic_collection_setup(collection_name=collection_name, on_disk_vectors=on_disk_vectors,
on_disk_payload=on_disk_payload)
yield
drop_collection(collection_name=collection_name)


def assert_points(points, nonexisting_ids=None, with_vectors=False):
def assert_points(collection_name, points, nonexisting_ids=None, with_vectors=False):
ids = [point['id'] for point in points]
ids.extend(nonexisting_ids or [])

Expand All @@ -41,7 +39,7 @@ def assert_points(points, nonexisting_ids=None, with_vectors=False):
assert point.get('vector') == expected.get('vector')


def test_batch_update():
def test_batch_update(collection_name):
# Upsert and delete points
response = request_with_validation(
api="/collections/{collection_name}/points/batch",
Expand Down Expand Up @@ -106,8 +104,8 @@ def test_batch_update():
)
assert response.ok

assert_points(
[
assert_points(collection_name,
[
{
"id": 7,
"vector": [2.0, 1.0, 3.0, 4.0],
Expand All @@ -118,8 +116,8 @@ def test_batch_update():
with_vectors=True,
)

assert_points(
[
assert_points(collection_name,
[
{
"id": 9,
"vector": {
Expand Down Expand Up @@ -168,8 +166,8 @@ def test_batch_update():
)
assert response.ok

assert_points(
[
assert_points(collection_name,
[
{
"id": 7,
"vector": [9.0, 2.0, 4.0, 2.0],
Expand Down Expand Up @@ -210,8 +208,8 @@ def test_batch_update():
)
assert response.ok

assert_points(
[
assert_points(collection_name,
[
{
"id": 7,
"vector": [9.0, 2.0, 4.0, 2.0],
Expand All @@ -228,7 +226,7 @@ def test_batch_update():
)


def test_batch_update_payload():
def test_batch_update_payload(collection_name):
# Batch on multiple points
response = request_with_validation(
api="/collections/{collection_name}/points/batch",
Expand Down Expand Up @@ -257,8 +255,8 @@ def test_batch_update_payload():
)
assert response.ok

assert_points(
[
assert_points(collection_name,
[
{
"id": 1,
"payload": {
Expand Down Expand Up @@ -299,8 +297,8 @@ def test_batch_update_payload():
)
assert response.ok

assert_points(
[
assert_points(collection_name,
[
{
"id": 1,
"payload": {},
Expand Down Expand Up @@ -350,8 +348,8 @@ def test_batch_update_payload():
)
assert response.ok

assert_points(
[
assert_points(collection_name,
[
{
"id": 1,
"payload": {
Expand Down
Loading

0 comments on commit 96a5a2b

Please sign in to comment.