| 1 |
###################################################################### |
| 2 |
# |
| 3 |
# File: test/unit/console_tool/conftest.py |
| 4 |
# |
| 5 |
# Copyright 2023 Backblaze Inc. All Rights Reserved. |
| 6 |
# |
| 7 |
# License https://www.backblaze.com/using_b2_code.html |
| 8 |
# |
| 9 |
###################################################################### |
| 10 |
import os |
| 11 |
import sys |
| 12 |
|
| 13 |
import pytest |
| 14 |
|
| 15 |
import b2._internal.console_tool |
| 16 |
|
| 17 |
|
| 18 |
@pytest.fixture |
| 19 |
def cwd_path(tmp_path): |
| 20 |
"""Set up a test directory and return its path.""" |
| 21 |
prev_cwd = os.getcwd() |
| 22 |
os.chdir(tmp_path) |
| 23 |
yield tmp_path |
| 24 |
os.chdir(prev_cwd) |
| 25 |
|
| 26 |
|
| 27 |
@pytest.fixture |
| 28 |
def b2_cli_log_fix(caplog): |
| 29 |
caplog.set_level(0) # prevent pytest from blocking logs |
| 30 |
b2._internal.console_tool.logger.setLevel(0) # reset logger level to default |
| 31 |
|
| 32 |
|
| 33 |
@pytest.fixture |
| 34 |
def mock_stdin(monkeypatch): |
| 35 |
out_, in_ = os.pipe() |
| 36 |
monkeypatch.setattr(sys, 'stdin', os.fdopen(out_)) |
| 37 |
in_f = open(in_, 'w') |
| 38 |
yield in_f |
| 39 |
in_f.close() |