Skip to content

Commit

Permalink
Merge pull request #156 from gregoil/fix_services_release_and_doc
Browse files Browse the repository at this point in the history
Finalized services and initialized shell global result
  • Loading branch information
UnDarkle committed Jul 31, 2019
2 parents 03c20f2 + 2b3dfe2 commit 3f5fda1
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 14 deletions.
8 changes: 8 additions & 0 deletions docs/advanced/custom_output_handlers.rst
Expand Up @@ -10,6 +10,14 @@ Third Party Output Handlers
- Plugin to the amazing `Report Portal <http://reportportal.io/>`_ system,
that enables viewing test results and investigating them.

* `rotest-progress <https://github.com/gregoil/rotest-progress>`_

- Uses `tqdm` to give you two user-friendly output handlers (tested on Linuex only):
`full_progress` which shows the general progress of the run,
and `progress` which shows the progress of the current component and can
be used with other handlers that write to the screen, e.g. `logdebug`.


How to Make Your Own Output Handler
===================================

Expand Down
6 changes: 6 additions & 0 deletions docs/configurations.rst
Expand Up @@ -205,6 +205,12 @@ Define it in the following ways:
* Use the default, which is ``[]``.

Shell Output Handlers
----------------------

``rotest shell`` enables defining output handlers for components run in it,
(see :ref:`output_handlers`). The default value is ``["logdebug"]``.

Discoverer Blacklist
--------------------

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -3,7 +3,7 @@
from setuptools import setup, find_packages


__version__ = "7.9.0"
__version__ = "7.9.1"

result_handlers = [
"db = rotest.core.result.handlers.db_handler:DBHandler",
Expand Down
20 changes: 9 additions & 11 deletions src/rotest/management/client/manager.py
Expand Up @@ -37,7 +37,7 @@ class ClientResourceManager(AbstractClient):
Responsible for locking resources and preparing them for work,
also for the resources cleanup procedure and release.
Preparation includes validating, reseting and initializing resources.
Preparation includes validating, resetting and initializing resources.
Attributes:
locked_resources (list): resources locked and initialized by the client
Expand Down Expand Up @@ -77,8 +77,8 @@ def disconnect(self):
Raises:
RuntimeError: wasn't connected in the first place.
"""
self._release_locked_resources()
if self.is_connected():
self._release_locked_resources()
self.requester.request(CleanupUser, method="post",
data=TokenModel({"token": self.token}))
super(ClientResourceManager, self).disconnect()
Expand Down Expand Up @@ -137,9 +137,7 @@ def _cleanup_resources(self, resources):

for resource in resources:
try:
resource.logger.debug("Finalizing resource %r", resource.name)
resource.finalize()
resource.logger.debug("Resource %r Finalized", resource.name)

except Exception as err:
# A finalize failure should not stop other resources from
Expand Down Expand Up @@ -257,6 +255,13 @@ def _release_resources(self, resources):
release_requests = [res.name
for res in resources if res.DATA_CLASS is not None]

for resource in resources[:]:
if resource in self.locked_resources:
self.locked_resources.remove(resource)

if resource in self.unused_resources:
self.unused_resources.remove(resource)

if len(release_requests) > 0:
request_data = ReleaseResourcesParamsModel({
"resources": release_requests,
Expand All @@ -269,13 +274,6 @@ def _release_resources(self, resources):
if isinstance(response, FailureResponseModel):
raise ResourceReleaseError(response.errors)

for resource in resources:
if resource in self.locked_resources:
self.locked_resources.remove(resource)

if resource in self.unused_resources:
self.unused_resources.remove(resource)

def _find_matching_resources(self, descriptor, resources):
"""Get all similar resources that match the resource descriptor.
Expand Down
6 changes: 4 additions & 2 deletions src/rotest/management/utils/shell.py
Expand Up @@ -148,12 +148,14 @@ def run_test(test_class, config=default_config, debug=ENABLE_DEBUG, **kwargs):


def create_result():
"""Create the result object for running tests in the shell."""
print("Creating output handlers:", SHELL_OUTPUT_HANDLERS)
"""Initialize the global result object for running tests in the shell."""
print("Creating result object with handlers:", SHELL_OUTPUT_HANDLERS)
global result_object
result_object = Result(stream=sys.stdout, descriptions=None,
outputs=SHELL_OUTPUT_HANDLERS, main_test=None)

result_object.startTestRun()


def main():
django.setup()
Expand Down

0 comments on commit 3f5fda1

Please sign in to comment.