Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Optimize unittest loading
Hello everyone,

I have a problem, let me describe it.

I've written a unittest (actually, an integration test) for the whole flow of my application (the flow from incoming request to outgoing response). All works fine, but...
When I run my test, the system is preparing (loads all imports, components, modules) for the whole flow, and this takes too much time (over 3 minutes) only for preparation, and only then it runs the test (which takes only 10 seconds).

How can I speedup my test runner? Is there a way to optimize the process? Maybe somehow disable forcing of *.pyc files regeneration or some other way?
Missing information:
  • Code listing
  • Your OS
  • Memory available and other platform
  • Python version
1. Code sample (this is only one file):
# TODO: this class will extends from core HttpCommunicator
from typing import Optional

from contracts import contract

from config import SPWContainerDsb
from provider.request.dsb_request import DsbRequest
from provider.service.request_builder.http import DsbHttpRequestBuilderFactory
from transport.http_entities import HttpRequest
from transport.http_request_to_spw_transformer import HttpRequestToSpwTransformer
from transport.spw_xml_element_transformer import SpwRequestXmlElementTransformer
from transport.transport import Message, TransportAsync

class DsbCommunicator:
    def __init__(
            transport: TransportAsync,
            http_request_builder_factory: DsbHttpRequestBuilderFactory,
            spw_request_builder: HttpRequestToSpwTransformer,
            spw_request_xml_element_transformer: SpwRequestXmlElementTransformer
        self.__transport = transport
        self.__http_request_builder_factory = http_request_builder_factory
        self.__spw_request_builder = spw_request_builder
        self.__spw_request_xml_element_transformer = spw_request_xml_element_transformer
        self.__last_spw_message = None

    def send_request(self, dsb_request: DsbRequest):
        self.__last_spw_message = None
        http_request = self.__get_http_request(dsb_request)
        spw_message = self.__get_spw_message(http_request)
        self.__last_spw_message = spw_message


    @contract(dsb_request='$DsbRequest', returns='$HttpRequest')
    def __get_http_request(self, dsb_request: DsbRequest) -> HttpRequest:
        http_request_builder = self.__http_request_builder_factory.get_http_request_builder(dsb_request)
        http_request = http_request_builder.create_http_request(dsb_request)

        return http_request

    @contract(http_request='$HttpRequest', returns='$Message')
    def __get_spw_message(self, http_request: HttpRequest) -> Message:
        spw_request = self.__spw_request_builder.to_spw_request(http_request)
        spw_request_element = self.__spw_request_xml_element_transformer.to_element(spw_request)
        spw_body = spw_request_element.to_string()
        message = Message(spw_body, SPWContainerDsb(spw_body))

        return message

    def get_last_spw_message(self) -> Optional[Message]:
        return self.__last_spw_message

2. Windows 10
3. 32Gb
4. Python 3.5
I found performance problem in my code: using PyContracts library. It was analyse too match code and rules via inspect library.

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Importing/loading a library file (.so) tomasby 0 62 Aug-24-2019, 08:13 PM
Last Post: tomasby
  How to pass a dictionary as an argument inside setup function of unittest nilaybnrj 1 262 May-11-2019, 03:18 AM
Last Post: keames
  cannot import scipy.optimize.Bounds larkypython 2 470 May-05-2019, 04:09 AM
Last Post: larkypython
  Error loading location on openweathermap via API with Kivy Gigux 10 547 Apr-24-2019, 06:08 PM
Last Post: Yoriz
  Help loading INT from a file. lovepeace 1 177 Apr-13-2019, 12:55 PM
Last Post: ichabod801
  Issue In Loading Textblob in jupyter Shivi_Bhatia 1 569 Apr-01-2019, 06:50 PM
Last Post: perfringo
  Getting error while loading excel(.xlsx) file using openpyxl module shubhamjainj 1 1,185 Mar-01-2019, 01:05 PM
Last Post: buran
  unittest.assertEqual giving failure on result although it's ok. FWendeburg 3 238 Feb-17-2019, 08:58 AM
Last Post: buran
  error creating new object after loading pickled objects from file arogers 2 373 Feb-02-2019, 10:43 AM
Last Post: Larz60+
  Python unittest - running multiple tests from CSV file asheru93 0 316 Jan-21-2019, 08:26 AM
Last Post: asheru93

Forum Jump:

Users browsing this thread: 1 Guest(s)