Пример #1
0
    def setUp(self):
        # Prevent args passed to test runner from being passed to Locust
        del sys.argv[1:]

        locust.events = Events()
        self.environment = Environment(events=locust.events,
                                       catch_exceptions=False)
        self.runner = LocustRunner(self.environment, [])

        # When running the tests in Python 3 we get warnings about unclosed sockets.
        # This causes tests that depends on calls to sys.stderr to fail, so we'll
        # suppress those warnings. For more info see:
        # https://github.com/requests/requests/issues/1882
        try:
            warnings.filterwarnings(action="ignore",
                                    message="unclosed <socket object",
                                    category=ResourceWarning)
        except NameError:
            # ResourceWarning doesn't exist in Python 2, but since the warning only appears
            # on Python 3 we don't need to mock it. Instead we can happily ignore the exception
            pass

        # set up mocked logging handler
        self._logger_class = MockedLoggingHandler()
        self._logger_class.setLevel(logging.INFO)
        self._root_log_handlers = [h for h in logging.root.handlers]
        [logging.root.removeHandler(h) for h in logging.root.handlers]
        logging.root.addHandler(self._logger_class)
        logging.root.setLevel(logging.INFO)
        self.mocked_log = MockedLoggingHandler
Пример #2
0
    def setUp(self):
        # Prevent args passed to test runner from being passed to Locust
        del sys.argv[1:]

        locust.events = Events()
        self.environment = Environment(events=locust.events,
                                       catch_exceptions=False)
        self.runner = self.environment.create_local_runner()

        # When running the tests in Python 3 we get warnings about unclosed sockets.
        # This causes tests that depends on calls to sys.stderr to fail, so we'll
        # suppress those warnings. For more info see:
        # https://github.com/requests/requests/issues/1882
        warnings.filterwarnings(action="ignore",
                                message="unclosed <socket object",
                                category=ResourceWarning)
        warnings.filterwarnings(action="ignore",
                                message="unclosed context <zmq.green.Context",
                                category=ResourceWarning)

        # set up mocked logging handler
        self._logger_class = MockedLoggingHandler()
        self._logger_class.setLevel(logging.INFO)
        self._root_log_handlers = [h for h in logging.root.handlers]
        [logging.root.removeHandler(h) for h in logging.root.handlers]
        logging.root.addHandler(self._logger_class)
        logging.root.setLevel(logging.INFO)
        self.mocked_log = MockedLoggingHandler

        # set unhandled exception flag to False
        log.unhandled_greenlet_exception = False
Пример #3
0
    def __init__(
            self, *,
            user_classes=[],
            shape_class=None,
            tags=None,
            exclude_tags=None,
            events=None,
            host=None,
            reset_stats=False,
            step_load=False,
            stop_timeout=None,
            catch_exceptions=True,
            parsed_options=None,
    ):
        if events:
            self.events = events
        else:
            self.events = Events()

        self.user_classes = user_classes
        self.shape_class = shape_class
        self.tags = tags
        self.exclude_tags = exclude_tags
        self.stats = RequestStats()
        self.host = host
        self.reset_stats = reset_stats
        self.step_load = step_load
        self.stop_timeout = stop_timeout
        self.catch_exceptions = catch_exceptions
        self.parsed_options = parsed_options

        self._filter_tasks_by_tags()
Пример #4
0
# Apply Gevent monkey patching of stdlib
from gevent import monkey as _monkey

_monkey.patch_all()

from locust.user.sequential_taskset import SequentialTaskSet
from locust.user import wait_time
from locust.user.task import task, tag, TaskSet
from locust.user.users import HttpUser, User
from locust.user.wait_time import between, constant, constant_pacing
from locust.shape import LoadTestShape
from locust.event import Events

events = Events()

__version__ = "1.2.3"
__all__ = (
    "SequentialTaskSet",
    "wait_time",
    "task", "tag", "TaskSet",
    "HttpUser", "User",
    "between", "constant", "constant_pacing",
    "events",
)

# Used for raising a DeprecationWarning if old Locust/HttpLocust is used
from .util.deprecation import DeprecatedLocustClass as Locust
from .util.deprecation import DeprecatedHttpLocustClass as HttpLocust