200-901 · Question #491
Drag and Drop Question Refer to the exhibit. Drag and drop the code from the bottom onto the box where the code is missing in the Python unittest to verify whether the function returns the correct…
The correct answer is formatted_name. This question tests the ability to correctly structure a basic Python unittest to import modules, call a function, and assert its return value.
Question
Drag and Drop Question Refer to the exhibit. Drag and drop the code from the bottom onto the box where the code is missing in the Python unittest to verify whether the function returns the correct values. Not all options are used. Answer:
Exhibit
Answer Area
Drag items
Correct arrangement
- formatted_name
Explanation
This question tests the ability to correctly structure a basic Python unittest to import modules, call a function, and assert its return value.
Approach. To complete the Python unittest correctly, the blanks should be filled as follows:
- First blank (
import ______): Drag 'unittest' into this box. Python's standard unit testing framework is accessed via theunittestmodule. - Second blank (
from name_function ______ formatted_name): Drag 'import' into this box. This is the correct syntax to import a specific function (formatted_name) from a module (name_function). - Third blank (
result = ______ ("User", "Name")): Drag 'formatted_name' into this box. Theresultvariable should store the output of calling theformatted_namefunction with the given arguments. - Fourth blank (
self.assertEqual(______, "User Name")): Drag 'result' into this box. TheassertEqualmethod compares the actual value (stored in theresultvariable) with the expected value ('User Name').
This sequence correctly sets up a unit test: importing the necessary modules, calling the function under test, and then asserting that its return value matches the expected output.
Common mistakes.
- common_mistake. The most common mistakes, as seen in the provided incorrect attempt, include:
- Using 'export' instead of 'formatted_name' for the function call (e.g.,
result = export("User", "Name")). 'export' is not a standard Python keyword or function for this purpose, especially not for calling a function namedformatted_name. - Using 'formatted_name' instead of 'result' in the
assertEqualcall (e.g.,self.assertEqual(formatted_name, "User Name")).formatted_namerefers to the function itself, not the value returned by calling the function. The assertion needs to compare the result of the function call with the expected value. - Other incorrect choices like 'unit' or 'name' are not appropriate module names, keywords, or variables for the given context.
Concept tested. Python unit testing fundamentals, including importing modules (unittest and custom functions), calling functions, and using assertion methods (assertEqual) within a unittest.TestCase class.
Reference. null
Topics
Community Discussion
No community discussion yet for this question.
