|
5 | 5 | @pytest.fixture |
6 | 6 | def sorting_test_client(client_factory: ClientFactory): |
7 | 7 | client = client_factory() |
8 | | - client.collections.delete_all() |
9 | | - yield client |
10 | | - client.collections.delete_all() |
11 | | - client.close() |
| 8 | + try: |
| 9 | + yield client |
| 10 | + finally: |
| 11 | + client.close() |
12 | 12 |
|
13 | 13 |
|
14 | 14 | def test_collections_list_all_sorting(sorting_test_client): |
15 | 15 | """Test that collections.list_all() returns collections sorted alphabetically by key.""" |
16 | 16 |
|
17 | 17 | client = sorting_test_client |
18 | 18 |
|
19 | | - # Create collections with names in non-alphabetical order |
20 | | - client.collections.create(name="TestCollectionC") |
21 | | - client.collections.create(name="TestCollectionA") |
22 | | - client.collections.create(name="TestCollectionB") |
23 | | - |
24 | | - # Get all collections |
25 | | - collections = client.collections.list_all() |
26 | | - |
27 | | - # Get the keys and filter only our test collections |
28 | | - collection_keys = list(collections.keys()) |
29 | | - test_collections = [k for k in collection_keys if k.startswith("TestCollection")] |
30 | | - |
31 | | - # Verify they are in alphabetical order |
32 | | - assert test_collections == sorted(test_collections) |
33 | | - |
34 | | - # Test with simple=False as well |
35 | | - collections = client.collections.list_all(simple=False) |
36 | | - collection_keys = list(collections.keys()) |
37 | | - test_collections = [k for k in collection_keys if k.startswith("TestCollection")] |
38 | | - assert test_collections == sorted(test_collections) |
39 | | - |
40 | | - # Clean up |
41 | | - client.collections.delete(["TestCollectionA", "TestCollectionB", "TestCollectionC"]) |
| 19 | + try: |
| 20 | + # Create collections with names in non-alphabetical order |
| 21 | + client.collections.create(name="SortingTestCollectionC") |
| 22 | + client.collections.create(name="SortingTestCollectionA") |
| 23 | + client.collections.create(name="SortingTestCollectionB") |
| 24 | + |
| 25 | + # Get all collections |
| 26 | + collections = client.collections.list_all() |
| 27 | + |
| 28 | + # Get the keys and filter only our test collections |
| 29 | + collection_keys = list(collections.keys()) |
| 30 | + test_collections = [k for k in collection_keys if k.startswith("SortingTestCollection")] |
| 31 | + |
| 32 | + # Verify they are in alphabetical order |
| 33 | + assert test_collections == sorted(test_collections) |
| 34 | + |
| 35 | + # Test with simple=False as well |
| 36 | + collections = client.collections.list_all(simple=False) |
| 37 | + collection_keys = list(collections.keys()) |
| 38 | + test_collections = [k for k in collection_keys if k.startswith("SortingTestCollection")] |
| 39 | + assert test_collections == sorted(test_collections) |
| 40 | + |
| 41 | + finally: |
| 42 | + # Clean up |
| 43 | + client.collections.delete( |
| 44 | + ["SortingTestCollectionA", "SortingTestCollectionB", "SortingTestCollectionC"] |
| 45 | + ) |
0 commit comments