Skip to content

Commit

Permalink
[BUGFIX] Create persist log directory if it does not exist (#513)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmbannon authored Mar 8, 2023
1 parent 6480272 commit fd1934b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/ytdl_sub/cli/main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import gc
import os
import sys
from datetime import datetime
from pathlib import Path
Expand Down Expand Up @@ -54,6 +55,7 @@ def _maybe_write_subscription_log_file(
if not success:
Logger.log_exit_exception(exception=exception, log_filepath=persist_log_path)

os.makedirs(os.path.dirname(persist_log_path), exist_ok=True)
FileHandler.copy(Logger.debug_log_filename(), persist_log_path)


Expand Down
12 changes: 10 additions & 2 deletions tests/unit/cli/test_main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import os.path
import re
import shutil
import tempfile
import time
from pathlib import Path
Expand All @@ -16,9 +18,15 @@


@pytest.fixture
def persist_logs_directory():
def persist_logs_directory() -> str:
# Delete the temp_dir on creation
with tempfile.TemporaryDirectory() as temp_dir:
yield temp_dir
pass

yield temp_dir

if os.path.isdir(temp_dir):
shutil.rmtree(temp_dir)


@pytest.fixture
Expand Down

0 comments on commit fd1934b

Please sign in to comment.