Back

Welcome To Software Engineering Practices, Part 2

Introduction

Introcduction:tv: In part 2 of software engineering practices, you’ll learn about the following practices of software engineering and how they apply in data science.

Testing

Testing:tv:

Testing your code is essential before deployment. It helps you catch errors and faulty conclusions before they make any major impact.

Today, employers are looking for data scientists with the skills to properly prepare their code for an industry setting, which includes testing their code.

Testing and Data Science

Testing:tv:

Unit Test

Testing:tv:

We want to test our functions in a way that is repeatable and automated. Ideally, we’d run a test program that runs all our unit tests and cleanly lets us know which ones failed and which ones succeeded. Fortunately, there are great tools available in Python that we can use to create effective unit tests!

Unit test advantages and disadvantages

The advantage of unit tests is that they are isolated from the rest of your program, and thus, no dependencies are involved. They don’t require access to databases, APIs, or other external sources of information. However, passing unit tests isn’t always enough to prove that our program is working successfully. To show that all the parts of our program work with each other properly, communicating and transferring data between them correctly, we use integration tests. In this lesson, we’ll focus on unit tests; however, when you start building larger programs, you will want to use integration tests as well.

To learn more about integration testing and how integration tests relate to unit tests, see Integration Testing. That article contains other very useful links as well.

Unit Testing Tools

Unit Testing:tv:

Unit Testing Tools

To install pytest, run pip install -U pytest in your terminal. You can see more information on getting started here.

test_ is the default; if you wish to change this, you can learn how in this pytest configuration.

In the test output, periods represent successful unit tests and Fs represent failed unit tests. Since all you see is which test functions failed, it’s wise to have only one assert statement per test. Otherwise, you won’t know exactly how many tests failed or which tests failed.

Your test won’t be stopped by failed assert statements, but it will stop if you have syntax errors.

Exercise: Unit tests

Download README.md, compute_launch.py, and test_compute_launch.py.

Follow the instructions in README.md to complete the exercise.

Supporting Materials

TDD:tv:

Test-driven development for data science is relatively new and is experiencing a lot of experimentation and breakthroughs. You can learn more about it by exploring the following resources.

Data Science TDD TDD for Data Science TDD is Essential for Good Data Science Here’s Why Testing Your Code (general python TDD)

Logging

Logging:tv:

Logging Logging is valuable for understanding the events that occur while running your program. For example, if you run your model overnight and the results the following morning are not what you expect, log messages can help you understand more about the context in those results occurred. Let’s learn about the qualities that make a log message effective.

Log Messages

Logging is the process of recording messages to describe events that have occurred while running your software. Let’s take a look at a few examples, and learn tips for writing good log messages. image

Code Reviews

Code Reviews:tv:

Code reviews benefit everyone in a team to promote best programming practices and prepare code for production. Let’s go over what to look for in a code review and some tips on how to conduct one.

Code reviews Code review best practices

Questions for a Code Review

First, let’s look over some of the questions we might ask ourselves while reviewing code. These are drawn from the concepts we’ve covered in these last two lessons.

Is the code clean and modular?

Is the code efficient?

Is the documentation effective?

Is the code well tested?

** Is the logging effective?**

Tips for Conducting a Code Review

image

Conclusion

conclusion:tv:

Back