Skip to content

Commit 38ff3f1

Browse files
author
deathaxe
authored
Ensure output folders exist (#243)
This commit... 1. simplifies output path creation via `exist_ok=True` 2. omits removing output file as it is overwritten by `open(..., "w")`
1 parent e72a837 commit 38ff3f1

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

unittesting/mixin.py

+4-7
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,8 @@ def load_unittesting_settings(self, package, options):
100100
def default_output(self, package):
101101
outputdir = os.path.join(
102102
sublime.packages_path(), 'User', 'UnitTesting', "tests_output")
103-
if not os.path.isdir(outputdir):
104-
os.makedirs(outputdir)
105-
outfile = os.path.join(outputdir, package)
106-
return outfile
103+
os.makedirs(outputdir, exist_ok=True)
104+
return os.path.join(outputdir, package)
107105

108106
def load_stream(self, package, settings):
109107
output = settings["output"]
@@ -117,9 +115,8 @@ def load_stream(self, package, settings):
117115
if sublime.platform() == "windows":
118116
output = output.replace("/", "\\")
119117
output = os.path.join(sublime.packages_path(), package, output)
120-
if os.path.exists(output):
121-
os.remove(output)
122-
stream = open(output, "w")
118+
os.makedirs(os.path.dirname(output), exist_ok=True)
119+
stream = open(output, "w", encoding="utf-8")
123120

124121
return stream
125122

0 commit comments

Comments
 (0)