Skip to content

Commit eff91bd

Browse files
authored
Merge pull request #291 from seleniumbase/command-line-option-to-archive-logs
Add a command-line option to archive old log files rather than deleting them.
2 parents cb9a2d2 + 70300d9 commit eff91bd

File tree

4 files changed

+27
-18
lines changed

4 files changed

+27
-18
lines changed

seleniumbase/core/log_helper.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def get_html_source_with_base_href(driver, page_source):
101101
return ''
102102

103103

104-
def log_folder_setup(log_path):
104+
def log_folder_setup(log_path, archive_logs=False):
105105
""" Handle Logging """
106106
if log_path.endswith("/"):
107107
log_path = log_path[:-1]
@@ -125,5 +125,5 @@ def log_folder_setup(log_path):
125125
archived_folder, int(time.time()))
126126
shutil.move(log_path, archived_logs)
127127
os.makedirs(log_path)
128-
if not settings.ARCHIVE_EXISTING_LOGS:
128+
if not settings.ARCHIVE_EXISTING_LOGS and not archive_logs:
129129
shutil.rmtree(archived_logs)

seleniumbase/plugins/base_plugin.py

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,18 @@
1717

1818
class Base(Plugin):
1919
"""
20-
The base_plugin includes the following variables for nosetest runs:
21-
self.env -- The environment for the tests to use (Usage: --env=ENV)
22-
self.data -- Any extra data to pass to the tests (Usage: --data=DATA)
23-
self.log_path -- The directory where log files get saved to
24-
(Usage: --log_path=LOG_PATH)
25-
self.report -- The option to create a fancy report after tests complete
26-
(Usage: --report)
27-
self.show_report -- If self.report is turned on, then the report will
28-
display immediately after tests complete their run.
29-
Only use this when running tests locally, as this will
30-
pause the test run until the report window is closed.
31-
(Usage: --show_report)
20+
The base_plugin includes the following command-line options for nosetests:
21+
--env=ENV (Set a test environment. Use "self.env" to access env in tests.)
22+
--data=DATA (Extra data to pass to tests. Use "self.data" in tests.)
23+
--log_path=LOG_PATH (The directory where log files get saved to.)
24+
--archive_logs (Archive old log files instead of deleting them.)
25+
--report (The option to create a fancy report after tests complete.)
26+
--show_report If self.report is turned on, then the report will
27+
display immediately after tests complete their run.
28+
Only use this when running tests locally, as this will
29+
pause the test run until the report window is closed.
3230
"""
33-
name = 'testing_base' # Usage: --with-testing_base
31+
name = 'testing_base' # Usage: --with-testing_base (Enabled by default)
3432

3533
def options(self, parser, env):
3634
super(Base, self).options(parser, env=env)
@@ -55,6 +53,11 @@ def options(self, parser, env):
5553
'--log_path', dest='log_path',
5654
default='latest_logs/',
5755
help='Where the log files are saved.')
56+
parser.add_option(
57+
'--archive_logs', action="store_true",
58+
dest='archive_logs',
59+
default=False,
60+
help="Archive old log files instead of deleting them.")
5861
parser.add_option(
5962
'--report', action="store_true", dest='report',
6063
default=False,
@@ -89,7 +92,8 @@ def configure(self, options, conf):
8992
self.test_count = 0
9093
self.import_error = False
9194
log_path = options.log_path
92-
log_helper.log_folder_setup(log_path)
95+
archive_logs = options.archive_logs
96+
log_helper.log_folder_setup(log_path, archive_logs)
9397
if self.report_on:
9498
report_helper.clear_out_old_report_logs(archive_past_runs=False)
9599

seleniumbase/plugins/pytest_plugin.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ def pytest_addoption(parser):
5757
parser.addoption('--log_path', dest='log_path',
5858
default='latest_logs/',
5959
help='Where the log files are saved.')
60+
parser.addoption('--archive_logs', action="store_true",
61+
dest='archive_logs',
62+
default=False,
63+
help="Archive old log files instead of deleting them.")
6064
parser.addoption('--with-db_reporting', action="store_true",
6165
dest='with_db_reporting',
6266
default=False,
@@ -189,6 +193,7 @@ def pytest_configure(config):
189193
sb_config.cap_file = config.getoption('cap_file')
190194
sb_config.database_env = config.getoption('database_env')
191195
sb_config.log_path = config.getoption('log_path')
196+
sb_config.archive_logs = config.getoption('archive_logs')
192197
sb_config.demo_mode = config.getoption('demo_mode')
193198
sb_config.demo_sleep = config.getoption('demo_sleep')
194199
sb_config.highlights = config.getoption('highlights')
@@ -200,7 +205,7 @@ def pytest_configure(config):
200205
sb_config.timeout_multiplier = config.getoption('timeout_multiplier')
201206

202207
if sb_config.with_testing_base:
203-
log_helper.log_folder_setup(sb_config.log_path)
208+
log_helper.log_folder_setup(sb_config.log_path, sb_config.archive_logs)
204209
proxy_helper.remove_proxy_zip_if_present()
205210

206211

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
setup(
1919
name='seleniumbase',
20-
version='1.21.2',
20+
version='1.21.3',
2121
description='Reliable Browser Automation & Testing Framework',
2222
long_description=long_description,
2323
long_description_content_type='text/markdown',

0 commit comments

Comments
 (0)