|
1 | 1 | # The MIT License (MIT)
|
2 |
| -# Copyright (c) 2017 Microsoft Corporation |
| 2 | +# Copyright (c) Microsoft Corporation. All rights reserved. |
3 | 3 |
|
4 |
| -# Permission is hereby granted, free of charge, to any person obtaining a copy |
5 |
| -# of this software and associated documentation files (the "Software"), to deal |
6 |
| -# in the Software without restriction, including without limitation the rights |
7 |
| -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
8 |
| -# copies of the Software, and to permit persons to whom the Software is |
9 |
| -# furnished to do so, subject to the following conditions: |
| 4 | +import test_config |
| 5 | +from azure.cosmos import CosmosClient as CosmosSyncClient |
10 | 6 |
|
11 |
| -# The above copyright notice and this permission notice shall be included in all |
12 |
| -# copies or substantial portions of the Software. |
| 7 | +cosmos_sync_client = CosmosSyncClient(test_config.TestConfig.host, test_config.TestConfig.masterKey) |
13 | 8 |
|
14 |
| -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
15 |
| -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
16 |
| -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
17 |
| -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
18 |
| -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
19 |
| -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
20 |
| -# SOFTWARE |
21 | 9 |
|
22 |
| -# pytest fixture 'teardown' is called at the end of a test run to clean up resources |
| 10 | +def pytest_configure(config): |
| 11 | + """ |
| 12 | + Allows plugins and conftest files to perform initial configuration. |
| 13 | + This hook is called for every plugin and initial conftest |
| 14 | + file after command line options have been parsed. |
| 15 | + """ |
| 16 | + |
| 17 | + |
| 18 | +def pytest_sessionstart(session): |
| 19 | + """ |
| 20 | + Called after the Session object has been created and |
| 21 | + before performing collection and entering the run test loop. |
| 22 | + """ |
| 23 | + config = test_config.TestConfig |
| 24 | + config.create_database_if_not_exist(cosmos_sync_client) |
| 25 | + config.create_single_partition_container_if_not_exist(cosmos_sync_client) |
| 26 | + config.create_multi_partition_container_if_not_exist(cosmos_sync_client) |
23 | 27 |
|
24 |
| -import test_config |
25 |
| -import pytest |
26 |
| -import cleanup |
27 | 28 |
|
28 |
| -@pytest.fixture(scope="session") |
29 |
| -def teardown(request): |
| 29 | +def pytest_sessionfinish(session, exitstatus): |
| 30 | + """ |
| 31 | + Called after whole test run finished, right before |
| 32 | + returning the exit status to the system. |
| 33 | + """ |
| 34 | + config = test_config.TestConfig |
| 35 | + config.try_delete_database(cosmos_sync_client) |
30 | 36 |
|
31 |
| - def delete_test_database(): |
32 |
| - config = test_config._test_config |
33 |
| - cleanup.delete_database(config.TEST_DATABASE_ID) |
34 | 37 |
|
35 |
| - request.addfinalizer(delete_test_database) |
36 |
| - return None |
| 38 | +def pytest_unconfigure(config): |
| 39 | + """ |
| 40 | + called before test process is exited. |
| 41 | + """ |
0 commit comments