Python Tutorial: Understanding test result report
Want to learn more? Take the full course at https://learn.datacamp.com/courses/unit-testing-for-data-science-in-python at your own pace. More than a video, you'll learn hands-on coding & quickly apply skills to your daily work.
---
In this lesson, we will take a deeper look at the output generated when we run tests. This output is called the test result report and contains information that will help us fix bugs.
As an example, we will use the test module test_row_to_list.py, which we saw in the previous video lesson. It contains three unit tests for the row_to_list() function. The unit tests check if row_to_list() returns the correct return values for clean rows, rows missing area data and rows missing the tab separator respectively.
Running the tests in the IPython console produces lot of output. So much output that we had to truncate it in this slide. This is called the test result report. We will break this down into smaller pieces and understand them individually.
The first section provides information about the operating system, Python version, pytest package versions, the working directory and pytest plugins. There is not much to say about this section, so let's move ahead.
The next bit is important. The output says "collected 3 items", which means that pytest found three tests to run. This is accurate as the test module test_row_to_list.py contains three unit tests.
The next line contains the test module name, which is test_row_to_list.py, followed by the characters dot, capital F and dot. Each character represents the result of a unit test.
The character capital F stands for failure. A unit test fails if an exception is raised when running the unit test code.
This happens most often when the assert statement raises an AssertionError. This means that the function has a bug and we should fix it.
A unit test may also fail if a different exception is raised while running the unit test code. In this case, execution will stop before the assert statement is run.
For example, if we wrote None with a small n, this would raise a NameError. Since the assert statement did not run, we cannot conclude anything about the function under test from the capital F result. In this case, we should fix the unit test so that it can actually run the assert statement.
Dot means that the unit test passed. This means no exceptions were raised by the assert statement or any other part of the unit test.
For the test module test_row_to_list.py, the first test passed, the second failed and the third passed.
The next section contains detailed information about failed tests. We can see that the unit test test_on_missing_area() failed. The line raising the exception is marked by a greater than sign on the left. In this case, it is the assert statement.
The following lines marked with capital E on the left contains details of the exception. In this case, the assert statement raised an AssertionError.
The lines which contain the word "where" displays any return values that were calculated when running the assert statement. In this case, it shows that the actual return value of row_to_list() is a list containing an empty string and the string "293,410".
The expected return value is, of course, None.
The mismatch between the expected and actual value will be our starting point for debugging. We would have to figure out why row_to_list() returns a list instead of None in this case.
The final line is a test result summary, saying that "1 test failed, and 2 passed". Additionally, we also find out that the test took 0.03 seconds to run. That's really fast compared to the time we would need to test using the interpreter.
Now, let's practice reading test result reports.
#Python #PythonTutorial #DataCamp #Unit #Testing #DataScience #pytest
Что делает видео по-настоящему запоминающимся? Наверное, та самая атмосфера, которая заставляет забыть о времени. Когда вы заходите на RUVIDEO, чтобы посмотреть онлайн «Python Tutorial: Understanding test result report», вы рассчитываете на нечто большее, чем просто загрузку плеера. И мы это понимаем. Контент такого уровня заслуживает того, чтобы его смотрели в HD 1080, без дрожания картинки и бесконечного буферизации.
Честно говоря, Rutube сегодня — это кладезь уникальных находок, которые часто теряются в общем шуме. Мы же вытаскиваем на поверхность самое интересное. Будь то динамичный экшн, глубокий разбор темы от любимого автора или просто уютное видео для настроения — всё это доступно здесь бесплатно и без лишних формальностей. Никаких «заполните анкету, чтобы продолжить». Только вы, ваш экран и качественный поток.
Если вас зацепило это видео, не забудьте взглянуть на похожие материалы в блоке справа. Мы откалибровали наши алгоритмы так, чтобы они подбирали контент не просто «по тегам», а по настроению и смыслу. Ведь в конечном итоге, онлайн-кинотеатр — это не склад файлов, а место, где каждый вечер можно найти свою историю. Приятного вам отдыха на RUVIDEO!
Видео взято из открытых источников Rutube. Если вы правообладатель, обратитесь к первоисточнику.