conftest.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. # -*- coding: utf-8 -*-
  2. '''
  3. tests.integration.conftest
  4. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  5. Integration tests PyTest configuration/fixtures
  6. '''
  7. # pylint: disable=unused-argument,redefined-outer-name
  8. # Import Python libs
  9. from __future__ import absolute_import, unicode_literals
  10. import logging
  11. from collections import OrderedDict
  12. # Import 3rd-party libs
  13. import psutil
  14. import pytest
  15. log = logging.getLogger(__name__)
  16. @pytest.fixture(scope='package', autouse=True)
  17. def default_session_daemons(request,
  18. log_server,
  19. session_salt_master,
  20. session_salt_minion,
  21. session_secondary_salt_minion,
  22. ):
  23. request.session.stats_processes.update(OrderedDict((
  24. ('Salt Master', psutil.Process(session_salt_master.pid)),
  25. ('Salt Minion', psutil.Process(session_salt_minion.pid)),
  26. ('Salt Sub Minion', psutil.Process(session_secondary_salt_minion.pid)),
  27. )).items())
  28. # Run tests
  29. yield
  30. # Stop daemons now(they would be stopped at the end of the test run session
  31. for daemon in (session_secondary_salt_minion, session_salt_minion, session_salt_master):
  32. try:
  33. daemon.terminate()
  34. except Exception as exc: # pylint: disable=broad-except
  35. log.warning('Failed to terminate daemon: %s', daemon.__class__.__name__)