Skip to main content

Posts

How to Run Unit Tests Without Testing Your Patience More often than not, the software we write directly interacts with what we would label as “dirty” services. In layman’s terms: services that are crucial to our application, but whose interactions have intended but undesired side-effects—that is, undesired in the context of an autonomous test run. For example: perhaps we’re writing a social app and want to test out our new ‘Post to Facebook feature’, but don’t want to  actually  post to Facebook every time we run our test suite. The Python  unittest  library includes a subpackage named  unittest.mock —or if you declare it as a dependency, simply  mock —which provides extremely powerful and useful means by which to mock and stub out these undesired side-effects. Note:  mock  is  newly included  in the standard library as of Python 3.3; prior distributions will have to use the Mock library downloadable via  PyPI . Fear System Calls To give you another example, and one tha
What is Mock in python?... Why do we use Mock in Python?? Where to use Mock in python??? -------------------------------------------------------------------------------------------------------------------------- The Python Mock Module enables you to create missing objects for your designs or reproduce expensive or volatile objects for your tests. With judicious use, mocks are an invaluable part of design, development, and testing. Reasons to Mock There are times when a test resource is either unavailable or unsuitable. Perhaps the resource is being developed in parallel with the test subject. It may then be incomplete or too unstable to be reliable. The resource may be too costly. If the resource is a third-party product, its high price tag can disqualify its use for testing. Setting up the resource might be complex, taking up hardware and time that could be used elsewhere. If the resource is a data source, setting up its data set, one that mimics real-world co
How to create & use pylint in python???  Introduction:  Pylint  is a source code bug and quality checker for the Python programming language. It follows the style recommended by PEP 8, the Python style guide. It is similar to Pychecker but includes the following features: Checking the length of each line. Pylint   is a Python tool that checks a module for coding standards. According to the TurboGears project coding guidelines,   PEP8   is the standard and pylint is a good mechanical test to help us in attaining that goal. The range of checks run from Python errors, missing docstrings, unused imports, unintended redefinition of built-ins, to bad naming and more.  Installation: You can simply install pylint: easy_install pylint or pip install pylint if you want to use django-python plugin , then use " pip install pylint-django ". & you can create custom config file of pylint:   pylint --generate-rcfile > ~/.pylintrc