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
  unittest mock and patch piscvau 1 162 Nov-08-2019, 03:23 PM
Last Post: ichabod801
  is there a way to optimize my checking system? GalaxyCoyote 4 250 Oct-13-2019, 09:18 AM
Last Post: perfringo
  cannot import scipy.optimize.Bounds larkypython 2 991 May-05-2019, 04:09 AM
Last Post: larkypython
  unittest.assertEqual giving failure on result although it's ok. FWendeburg 3 352 Feb-17-2019, 08:58 AM
Last Post: buran
  optimize choices in multiple if ---: statements Pedroski55 2 548 Dec-25-2018, 05:06 AM
Last Post: Pedroski55
  Automating unittest ichabod801 3 539 Oct-28-2018, 09:32 PM
Last Post: Gribouillis
  unittest for nested function fstefanov 2 855 Oct-15-2018, 01:43 PM
Last Post: jdjeffers
  Help me to complete unittest FooNtik 3 1,313 Jan-30-2018, 11:22 AM
Last Post: Gribouillis
  Executing single unittest over a sequence volcano63 1 1,745 May-11-2017, 11:11 AM
Last Post: volcano63

Forum Jump:

Users browsing this thread: 1 Guest(s)