Skip to content

Commit

Permalink
Fix Create Files Unit Test (#1117)
Browse files Browse the repository at this point in the history
* filter out pycache and prometheus logs from check

* fix formatting

* add filters to start_files too

* fix line length formatting
  • Loading branch information
Sara Adkins authored Jul 13, 2023
1 parent e10bbd1 commit 3794483
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,36 @@ def cleanup():

@pytest.fixture(scope="session", autouse=True)
def check_for_created_files():
start_files_root = _get_files(directory=r".")
start_files_root = [
f_path for f_path in _get_files(directory=r".") if "__pycache__" not in f_path
]
start_files_temp = _get_files(directory=tempfile.gettempdir())
yield
end_files_root = _get_files(directory=r".")
# allow creation of __pycache__ directories
end_files_root = [
f_path for f_path in _get_files(directory=r".") if "__pycache__" not in f_path
]
end_files_temp = _get_files(directory=tempfile.gettempdir())

max_allowed_number_created_files = 4
# GHA needs to create following files:
# pyproject.toml, CONTRIBUTING.md, LICENSE, setup.cfg
assert len(start_files_root) + max_allowed_number_created_files >= len(
end_files_root
), (
allowed_created_files = [
"pyproject.toml",
"CONTRIBUTING.md",
"LICENSE",
"setup.cfg",
"prometheus_logs.prom",
]
end_files_root = [
f_path
for f_path in end_files_root
if os.path.basename(f_path) not in allowed_created_files
]
start_files_root = [
f_path
for f_path in start_files_root
if os.path.basename(f_path) not in allowed_created_files
]
assert len(start_files_root) >= len(end_files_root), (
f"{len(end_files_root) - len(start_files_root)} "
f"files created in current working "
f"directory during pytest run. "
Expand Down

0 comments on commit 3794483

Please sign in to comment.