Chris McDonald | 2e9a09c | 2020-04-03 16:09:32 -0600 | [diff] [blame] | 1 | # -*- coding: utf-8 -*- |
| 2 | # Copyright 2020 The Chromium OS Authors. All rights reserved. |
| 3 | # Use of this source code is governed by a BSD-style license that can be |
| 4 | # found in the LICENSE file. |
| 5 | |
| 6 | """Configuration and fixtures for pytest. |
| 7 | |
| 8 | See the following doc link for an explanation of conftest.py and how it is used |
| 9 | by pytest: |
| 10 | https://docs.pytest.org/en/latest/fixture.html#conftest-py-sharing-fixture-functions |
| 11 | """ |
| 12 | |
| 13 | from __future__ import print_function |
| 14 | |
Chris McDonald | e53dde1 | 2020-04-07 13:43:14 -0600 | [diff] [blame^] | 15 | import pytest # pylint: disable=import-error |
Chris McDonald | 2e9a09c | 2020-04-03 16:09:32 -0600 | [diff] [blame] | 16 | |
| 17 | from chromite.lib import cidb |
| 18 | |
| 19 | |
Chris McDonald | e53dde1 | 2020-04-07 13:43:14 -0600 | [diff] [blame^] | 20 | @pytest.fixture(scope='class', autouse=True) |
Chris McDonald | 2e9a09c | 2020-04-03 16:09:32 -0600 | [diff] [blame] | 21 | def mock_cidb_connection(): |
| 22 | """Ensure that the CIDB connection factory is initialized as a mock. |
| 23 | |
| 24 | Unit tests should never connect to any live instances of CIDB and this |
| 25 | initialization ensures that they only ever get a mock connection instance. |
| 26 | |
| 27 | Previously cros_test_lib.TestProgram.runTests was responsible for globally |
| 28 | initializing this mock and multiple tests are flaky if this mock connection |
| 29 | is not initialized before any tests are run. |
| 30 | """ |
Chris McDonald | e53dde1 | 2020-04-07 13:43:14 -0600 | [diff] [blame^] | 31 | # pylint: disable=protected-access |
| 32 | cidb.CIDBConnectionFactory._ClearCIDBSetup() |
Chris McDonald | 2e9a09c | 2020-04-03 16:09:32 -0600 | [diff] [blame] | 33 | cidb.CIDBConnectionFactory.SetupMockCidb() |