Geek Logbook

Tech sea log book

Testing in Python: Pytest Vs Unit test

How important are the tests?

Testing is one of the most important skills we need to develop once we join the industry. In fact, knowing about testing is something that is not as evaluated as it could be. In general, the challenges are related to having logic related to programming skills or knowing about design systems. Testing is like a topping on your hamburger. But toppings are important if you want to have a good one. For us, it is the same.

So, not only because you need to understand how to test, but also because you will improve the chances of doing well in your job, it is advisable that it has an important foundation in testing.

What are the foundations of testing?

Testing is a branch by itself in technology. So, we are going to specify this connotation: we are talking about the testing from the point of view of a developer. Even more specific: we are talking about a developer who wants to understand some things about testing in Python. Once you learn testing as a developer, you will need to understand that testing is checking individual units of source code to ensure that your code is free of bugs. Then, It’s possible you’ll find a conversation between two tools used for testing: pytest Vs unittest.

Pytest is not in the standard library while unittest yes.

Booths are frameworks in the python library. The unit testing framework in Python known as unittest is a tool to validate the smallest unit of code. The tool is inspired by Java’s unit test

One significant difference is that unittest is part of the Python Standard Library (Link to the python documentation) in the pytest case you need to install it

Basic usage of the frameworks

After the installation, you will see that pytest is easier to work with. The code will be simpler while if you want to use unitest you will have to import modules and create test classes. Which could be hard if you are taking your first steps in testing your base code. In the case of unitttes your test must inherit from the TestCase. As we can read here: “A testcase is created by subclassing unittest.TestCase.” (Link to the documentation)

https://stackoverflow.com/questions/27954702/unittest-vs-pytest

Sources consulted

Leave a Reply

Your email address will not be published. Required fields are marked *.

*
*
You may use these <abbr title="HyperText Markup Language">HTML</abbr> tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>