-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
/tests folder : updated with latest changes from python_project_template
- Loading branch information
1 parent
c5fcd0f
commit 43e14a8
Showing
3 changed files
with
82 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
temp_* | ||
~$temp* |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,80 @@ | ||
import logging | ||
import os | ||
from glob import glob | ||
from pathlib import Path | ||
from shutil import rmtree | ||
|
||
import pytest | ||
from pytest import LogCaptureFixture | ||
|
||
|
||
@pytest.fixture(scope="package", autouse=True) | ||
def chdir(): | ||
os.chdir(Path(__file__).parent.absolute() / "test_working_directory") | ||
|
||
|
||
@pytest.fixture(scope="package", autouse=True) | ||
def test_dir(): | ||
return Path(__file__).parent.absolute() | ||
|
||
|
||
output_dirs = [ | ||
"results", | ||
] | ||
output_files = [ | ||
"*test*.pdf", | ||
] | ||
|
||
|
||
@pytest.fixture(autouse=True) | ||
def default_setup_and_teardown(caplog: LogCaptureFixture): | ||
_remove_output_dirs_and_files() | ||
yield | ||
_remove_output_dirs_and_files() | ||
|
||
|
||
def _remove_output_dirs_and_files(): | ||
for folder in output_dirs: | ||
rmtree(folder, ignore_errors=True) | ||
for pattern in output_files: | ||
for file in glob(pattern): | ||
file = Path(file) | ||
file.unlink(missing_ok=True) | ||
|
||
|
||
@pytest.fixture(autouse=True) | ||
def setup_logging(caplog: LogCaptureFixture): | ||
caplog.set_level("INFO") | ||
caplog.clear() | ||
|
||
|
||
@pytest.fixture(autouse=True) | ||
def logger(): | ||
return logging.getLogger() | ||
|
||
|
||
def pytest_addoption(parser): | ||
parser.addoption("--show", action="store", default=False) | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def show(request): | ||
return request.config.getoption("--show") == "True" | ||
import logging | ||
import os | ||
from pathlib import Path | ||
from shutil import rmtree | ||
|
||
import pytest | ||
|
||
|
||
@pytest.fixture(scope="package", autouse=True) | ||
def chdir() -> None: | ||
""" | ||
Fixture that changes the current working directory to the 'test_working_directory' folder. | ||
This fixture is automatically used for the entire package. | ||
""" | ||
os.chdir(Path(__file__).parent.absolute() / "test_working_directory") | ||
|
||
|
||
@pytest.fixture(scope="package", autouse=True) | ||
def test_dir() -> Path: | ||
""" | ||
Fixture that returns the absolute path of the directory containing the current file. | ||
This fixture is automatically used for the entire package. | ||
""" | ||
return Path(__file__).parent.absolute() | ||
|
||
|
||
output_dirs = [ | ||
"results", | ||
] | ||
output_files = [ | ||
"*test*.pdf", | ||
] | ||
|
||
|
||
@pytest.fixture(autouse=True) | ||
def default_setup_and_teardown(): | ||
""" | ||
Fixture that performs setup and teardown actions before and after each test function. | ||
It removes the output directories and files specified in 'output_dirs' and 'output_files' lists. | ||
""" | ||
_remove_output_dirs_and_files() | ||
yield | ||
_remove_output_dirs_and_files() | ||
|
||
|
||
def _remove_output_dirs_and_files() -> None: | ||
""" | ||
Helper function that removes the output directories and files specified in 'output_dirs' and 'output_files' lists. | ||
""" | ||
for folder in output_dirs: | ||
rmtree(folder, ignore_errors=True) | ||
for pattern in output_files: | ||
for file in Path.cwd().glob(pattern): | ||
_file = Path(file) | ||
_file.unlink(missing_ok=True) | ||
|
||
|
||
@pytest.fixture(autouse=True) | ||
def setup_logging(caplog: pytest.LogCaptureFixture) -> None: | ||
""" | ||
Fixture that sets up logging for each test function. | ||
It sets the log level to 'INFO' and clears the log capture. | ||
""" | ||
caplog.set_level("INFO") | ||
caplog.clear() | ||
|
||
|
||
@pytest.fixture(autouse=True) | ||
def logger() -> logging.Logger: | ||
"""Fixture that returns the logger object.""" | ||
return logging.getLogger() | ||
|
||
|
||
def pytest_addoption(parser): | ||
parser.addoption("--show", action="store", default=False) | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def show(request): | ||
return request.config.getoption("--show") == "True" |