Basic Primer _python-modules and packages. Best practices for inspect introspection modules in operational development?

Source: Internet
Author: User
Tags pprint

Brief introduction:

Description: This module provides a series of introspection functions to obtain information about the module/class/method/function/traceback/frame object/code object


Quick installation:

Built-in Modules


Test Related:

Inspect.ismodule (object), True/false

Description: Determine if object is a module

Inspect.isclass (object), True/false

Description: Determine if object is a class

Inspect.ismethod (object), True/false

Description: Determines whether an object is a method

Inspect.isfunction (object), True/false

Description: Determines whether a function

Inspect.isgeneratorfunction (object), True/false

Description: Determine if the generator function

Inspect.isgenerator (object), True/false

Description: Determine if the generator

Inspect.isbuiltin (object), True/false

Description: Whether it is a built-in object

Inspect.isabstract (object), True/false

Description: Whether it is an abstract base class


Source-Related:

Inspect.getdoc (object), str

Description: Gets the documentation information for object

Inspect.getfile (object), str

Description: Gets the original loaded file for object


Stack-Related:

Inspect.stack ([context]), list

Description: Gets the run-time context-based stack information


Best Practices:

1. Today the boss arranges the RPS Business services function/performance test under the test environment, as the initial version of RPS development is updated quickly, Want to quickly locate the Automation test plug-in anomaly, easy to quickly locate the problem, but partially rely on multiple sub-services plug-ins, in the test report needs to include the target host/plug-in name/function name/exception line/exception information and other fields, and the inspect built-in module just can extract runtime stack information ~

#!/usr/bin/env python# -*- coding: utf-8 -*-"" "## authors: limanman#  oschina: http://xmdevops.blog.51cto.com/# purpose:# "" "#  Description:  Import public module import  inspectimport pprint#  Description:  Import other modules Def rps_device ():    try:         raise ValueError,  ' with value error.  '      except ValueError, e:        return  Inspect.stack () [0][-4:-2], e.message    returndef rps_client ():     try:        raise ValueError,  ' With value  error. '     except valueerror, e:        return  inspect.stack () [0][-4:-2], e.message    returndef rps_testing (Add_data= None):     exec_ret_dicts = {         ' status ': 0,          ' errors ':  ' {0[0][1]}: {0[0][0]} with error ##  {0[1]} '     }    result = rps_device ()  or rps _client ()     exec_ret_dicts[' status '] = 0 if not result else  1    exec_ret_dicts[' Errors '] = exec_ret_dicts[' errors '].format (Result)     return exec_ret_dictsif __name__ ==  ' __main__ ':     pprint.pprint (rps_testing ())



This article is from the "Li-Yun Development Road" blog, please be sure to keep this source http://xmdevops.blog.51cto.com/11144840/1871279

Basic Primer _python-modules and packages. Best practices for inspect introspection modules in operational development?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.