In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article focuses on "what is the content of the Python testing framework", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn "what is the content of the Python testing framework"?
The following is an effective description of the Python testing framework. Python is an explanatory language, but this is not true. In fact, it is a language that can be accepted by people who have not studied programming or who are not computer majors.
There is a standard unit testing framework in the PythonPython testing framework (starting with Python 2.3). This is only an optional module in Python 2.2), which is very similar to the Java jUnit framework. The test case is structured in the same way as jUnit. Each class and module to be tested usually has its own test class. The test class contains a test device (fixture).
Import unittest from pprint import pprint import feedparser class FeedparserTest (unittest.TestCase): "A test class for the feedparser module." Def setUp (self): "set up data used in the tests. SetUp is called before each test function execution." Self.developerWorksUrl = "testData/developerworks.rss" def testParse09Rss (self): "Test a successful run of the parse function for a 0.91 RSS feed." Print "FeedparserTest.testParse09RSS ()" result = feedparser.parse (self.developerWorksUrl) pprint (result) self.assertEqual (0 Result ['bozo']) self.assert_ (result is not None) channel = result [' channel'] self.assert_ (channel is not None) chanDesc = channel ['description'] self.assertEqual (u'The latest content from IBM developerWorks' ChanDesc) items = result ['items'] self.assert_ (items is not None) self.assert_ (len (items) > 3) firstItem = items [0] title = firstItem [' title'] self.assertEqual (u'Build installation packages with solution installation and deployment technologies' Title) def tearDown (self): "" tear down any data used in tests tearDown is called after each test function execution. " Pass if _ _ name__ = ='_ _ main__': unittest.main ()
They are initialized in the setUp function. Each test is written as a separate test function in the test class. The unittest framework cycles back and forth between test functions, calling setUp, then testing functions, and then tearDown test functions. The above listing is a test class that implements the basic testing functions of the feedparser module. For the complete test class, see src/feedparserTest/FeedparserTest.py under the feedParserTest project.
The setUp function is responsible for preparing the test device to be used throughout the test. In this case, there is only the directory of the RSS file used for the test, which will be parsed by the test function. TestParse09Rss is the real test function. This function calls the feedparser.parse function, passes the RSS file for the test, and outputs the parsing result.
And perform basic checks through the assert function of the TestCase class. If the evaluation of any assert is not true, or any exception is thrown during execution. Unittest reports a test failure or error. The two lines of * * are responsible for running the test inside the test class by running the module directly.
To run the test class independently, you can run the FeedparserTest.py module in the same way as mentioned earlier. Select FeedparserTest.py in the Eclipse Navigator view. Then run it through Python Test Framework > Run. The startup configuration window appears. With the exception of the Base directory, keep the default values. The Base directory must be the directory of the feedParserTest project.
Only in this way can you find the RSS file (testData/developerworks.rss) in the current directory. Modify the settings of the base directory, and then click "Run". The output information is displayed on Console. You might want all the unit tests we write to be executed automatically as part of the build. Add the build snippet shown in listing 5 below to the build script.
The * line is the target declaration, which is the same as other scripts. Lines 2 to 6 invoke the py-test task. This part of the code will find all files ending with "Test.py" in the "src" directory and run all the tests. PYTHONPATH is set to "src", and the current working directory for test execution is the current directory ('.').
At this point, I believe you have a deeper understanding of "what is the content of the Python testing framework?" you might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
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.