Provides a new DB-API compliant connection to Impala as a pytest fixture. The same connection is used for all test methods in a class. The class may provide the following customizations: - get_db_name(): The name of the database to connect to. - auto_create_db(): If declared
(request)
| 451 | |
| 452 | @pytest.fixture(scope="class") |
| 453 | def conn(request): |
| 454 | """Provides a new DB-API compliant connection to Impala as a pytest fixture. The |
| 455 | same connection is used for all test methods in a class. The class may provide the |
| 456 | following customizations: |
| 457 | - get_db_name(): The name of the database to connect to. |
| 458 | - auto_create_db(): If declared and the method returns True, the database will |
| 459 | be created before tests run and dropped afterwards. If a database name is |
| 460 | provided by get_db_name(), it must not exist. Classes that use both |
| 461 | auto_create_db() and get_db_name() should generate a random name in |
| 462 | get_db_name() and cache it. |
| 463 | - get_conn_timeout(): The timeout, in seconds, to use for this connection. |
| 464 | The returned connection will have a 'db_name' property. |
| 465 | |
| 466 | DEPRECATED: |
| 467 | See the 'unique_database' fixture above to use Impala's custom python |
| 468 | API instead of DB-API. |
| 469 | """ |
| 470 | db_name = __call_cls_method_if_exists(request.cls, "get_db_name") |
| 471 | use_unique_conn = __call_cls_method_if_exists(request.cls, "auto_create_db") |
| 472 | timeout = __call_cls_method_if_exists(request.cls, "get_conn_timeout") or \ |
| 473 | DEFAULT_CONN_TIMEOUT |
| 474 | if use_unique_conn: |
| 475 | with __unique_conn(request.config, db_name=db_name, timeout=timeout) as conn: |
| 476 | yield conn |
| 477 | else: |
| 478 | with __auto_closed_conn(request.config, db_name=db_name, timeout=timeout) as conn: |
| 479 | yield conn |
| 480 | |
| 481 | |
| 482 | def __call_cls_method_if_exists(cls, method_name): |
nothing calls this directly
no test coverage detected