-
Notifications
You must be signed in to change notification settings - Fork 2
/
tox_cleanup.py
52 lines (38 loc) · 1.68 KB
/
tox_cleanup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
""" Cleans the project root directory before running tox tests.
Specifically, removes blowdrycss_settings.py from the project root before and after tox testing is finished.
The settings file is auto-generated as part of the integration testing.
If the settings file is in the root folder the py33+ could fail if the settings files changed. It is a strange
corner case that took a while to figure out since the python3 import system is different that py27.
Reproducing the error (scenario 1):
Go to project root where setup.py resides.
Activate virtual environment
Run: tox
If certain tests fail blowdrycss_settings.py could now be in the root directory.
Now subsequent py3x tests will fail.
Reproducing the error (scenario 2):
Go to project root where setup.py resides.
Activate virtual environment
Run: python setup.py install
blowdrycss_settings.py is now in the root directory.
Modify blowdrycss/blowdrycss/blowdrycss_settings.py
Run: tox
py3x tests will fail.
"""
# python 2.7
from __future__ import absolute_import, print_function
# builtins
from os import path, getcwd, remove
def main():
cwd = getcwd()
print('The tox_cleanup started in', cwd)
module_path = path.join(cwd, 'blowdrycss') # Prevent removal of settings file from module.
if cwd.endswith('blowdrycss') and path.isdir(module_path):
settings_file = path.join(cwd, 'blowdrycss_settings.py')
if path.isfile(settings_file):
remove(settings_file)
print('Deleted', settings_file)
else:
print('The file', settings_file, 'was not found.')
print('The tox_clean finished. Project root is clean.')
if __name__ == '__main__':
main()