In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
In this issue, the editor will bring you about how to analyze the Python testing framework. The article is rich in content and analyzed and described from a professional point of view. I hope you can get something after reading this article.
Many programmers would recommend using the Python test framework instead of manually testing for equality of assert statements, in which case the test will use self instead of ignoring it, and for developers familiar with the Python language, it is not as clear as the Python operator.
Recently, an industry-level Python testing framework has emerged, which means that Python tests can be written more succinctly, uniformly, and produce better results reports. More advanced testing frameworks are introduced here and their basic features are discussed. The wild days of Python testing are over.
But now the chaos is finally coming to an end. Several excellent test solutions have emerged in the community that provide conventions and common standards for test suites for hundreds of popular projects. The editor will introduce three popular testing frameworks and discuss the simple testing styles encouraged by the new generation of tools.
The second article discovers and selects tests to discuss the larger issue: how these frameworks automatically discover and classify project tests. * an article uses the Python test framework to generate test reports that discuss the powerful features these frameworks provide for viewing test results.
By learning the common practices of these three frameworks, you can not only better understand the Python packages written by other programmers, but also build elegant and powerful test suites for your applications. Candidate frameworks: three Python testing frameworks have three Python testing frameworks that are currently the most widely used. Here is a brief introduction to them in chronological order:
Often, developers working on Zope projects are like early pioneers. They needed to find and run tests on a large code base in a unified way, and developed the zope.testing package, which is still widely used today.
The zope.testing package only supports traditional Python testing styles such as unittest and doctest, but not the simplified styles supported by more modern frameworks. However, it provides a powerful hierarchical system in which directories that contain tests can rely on common setup code, which creates an environment for running tests for layers rather than for each test.
In py.test2004, Holger Krekel renamed his std package 'py',' because the original name was often confused with the standard library that came with Python. Although this package contains several other subpackages, the only part of the package now is its py.test framework.
The py.test framework establishes a new standard for Python testing, which is currently adopted by many developers. It provides elegant Python testing framework-compliant idioms for writing tests, allowing developers to write test suites in a very compact style.
The nose project was released in 2005, a year after py.test was renamed. It is written by Jason Pellerin and supports the same testing practices as py.test, but this package is easier to install and maintain. Although py.test has improved in some ways and is now easy to install, nose still maintains a reputation for ease of use. At Python conferences, developers are often seen wearing black T-shirts.
The nosetests command is printed on it, followed by a period indicating the success of the test. Interestingly, with the development of nose, it is often seen on the project mailing list that developers ask project leaders when their projects can be converted to nose.
Of the three frameworks, nose looks like the standard, py.test has a small but loyal user base, and zope.testing is only popular in projects based on the Zope framework. However, all three frameworks are actively maintained and each has some unique features. It is recommended that you understand their features and differences and choose a framework that suits your project.
The py.test framework accepts ordinary Python functions as tests without requiring tests in larger and heavier test classes, which opens a new era of Python testing. Because the nose framework supports the same idioms, these patterns are likely to become more and more popular. Suppose you want to check whether the true and false values of Python True and False are true
# test_old.py-The old way of doing things import unittest class TruthTest (unittest.TestCase): def testTrue (self): assert True = = 1 def testFalse (self): assert False = = 0 if _ _ name__ = ='_ main__': unittest.main ()
You see that? So much code is just to support two lines of test code! First, the code needs an import statement, which is completely independent of the code being tested, because the test itself simply ignores the module and uses only built-in Python values, such as True and False.
In addition, you create a class, but it doesn't support or enhance tests, because tests don't actually do anything with their self parameters. You need two fixed lines of code to run the test from the command line.
The above is the editor for you to share how to analyze the Python testing framework, if you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.