mirror of
https://github.com/Unstructured-IO/unstructured.git
synced 2025-08-18 13:45:45 +00:00
fix: teardown fixture for tests and update pre-commit-config (#2565)
Files were being created as a side effect from running tests in `test_unstructured/metrics/test_evaluate.py`. The updated decorator removes the created directory and its files after the tests run. Testing on the main branch, run `make test` or `pytest test_unstructured/metrics/test_evaluate.py` and files will be created. On this branch no files are created
This commit is contained in:
parent
8ea203adf7
commit
fe300fe56d
@ -56,15 +56,21 @@ DUMMY_DF_ELEMENT_TYPE = pd.DataFrame(
|
||||
|
||||
@pytest.fixture()
|
||||
def _cleanup_after_test():
|
||||
# This is where the test runs
|
||||
"""Fixture for removing side-effects of running tests in this file."""
|
||||
|
||||
def remove_generated_directories():
|
||||
"""Remove directories created from running tests."""
|
||||
|
||||
# Directories to be removed:
|
||||
target_dir_names = ["test_evaluate_results_cct", "test_evaluate_results_cct_txt"]
|
||||
subdirs = (d for d in os.scandir(TESTING_FILE_DIR) if d.is_dir())
|
||||
for d in subdirs:
|
||||
if d.name in target_dir_names:
|
||||
shutil.rmtree(d.path)
|
||||
|
||||
# Run test as normal
|
||||
yield
|
||||
|
||||
os.path.join(TESTING_FILE_DIR, UNSTRUCTURED_OUTPUT_DIRNAME)
|
||||
export_dir = os.path.join(TESTING_FILE_DIR, "test_evaluate_results_cct")
|
||||
|
||||
# Cleanup the directory and file
|
||||
if os.path.exists(export_dir):
|
||||
shutil.rmtree(export_dir)
|
||||
remove_generated_directories()
|
||||
|
||||
|
||||
@pytest.mark.skipif(is_in_docker, reason="Skipping this test in Docker container")
|
||||
|
Loading…
x
Reference in New Issue
Block a user