Skip to content

Commit 80e2f2e

Browse files
committed
edits
1 parent cbb565d commit 80e2f2e

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

days/10-12-pytest/README.md

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,42 @@
11
# Days 10-12 Test your code with pytest
22

3-
In this lesson I show you how to use pytest to test a simple guessing game. It might not be the easiest example for a beginner, but it allows me to show some real world issues you want to address in your test code.
3+
In this lesson I show you how to use `pytest` to test a simple guessing game. It might not be the easiest example for a beginner, but it allows me to show some real world issues you want to address in your test code.
44

5-
After pip installing the module, I quickly show you how to write a test with pytest and how it differs from the classic (more verbose) unittest syntax.
5+
After pip installing the module, I quickly show you how to write a test with `pytest` and how it differs from the classic (more verbose) `unittest` syntax.
66

77
Next I show you some tactics to mock out user inputs and random data, because test data needs to be predictable. We also learn how we can capture/test standard output of our program.
88

9-
Finally I show you some TDD or _test driven development_ in action by implementing Fizz Buzz by writing the tests first, in small incremental steps. You learn about the `pytest.mark.parametrize` decorator to elegantly handle repetitive tests.
9+
Finally I show you some TDD or _test driven development_ in action by implementing _Fizz Buzz_ by writing the tests first, in small incremental steps. You learn about the `pytest.mark.parametrize` decorator to elegantly handle repetitive tests.
1010

11-
The pytest framework is huge and this is just a subset of features. I hope this gives you a head start though to start writing (more) tests for your programs to produce more reliable software.
11+
The `pytest` framework is huge and this is just a subset of features. I hope this gives you a head start though to start writing (more) tests for your programs to produce more reliable software.
1212

13-
Be warned: mastering pytest might feel like possessing a super power!
13+
Be warned: mastering `pytest` might feel like possessing a super power!
1414

15-
## Day N: Setup + Learn pytest!
15+
## Day N: Setup + Learn pytest
1616

17-
Today you will pip install pytest and pytest-cov and watch the video lectures.
17+
Today you will pip install `pytest` and `pytest-cov` and watch the video lectures.
1818

1919
Start thinking about how you can write tests for your code ...
2020

21-
## Day N+1: Your Turn: Test your code!
21+
## Day N+1: Your Turn: Test your code
2222

2323
Head over to [PyBites Code Challenge 39 - Writing Tests With Pytest](https://codechalleng.es/challenges/39/) and start adding tests to your code or if you're already covered maybe you want to do that as contribution to an open source project?
2424

25-
By the way, notice that we use pytest for [our Bites](https://codechalleng.es/bites/) too. Under the _TESTS_ tab of each Bite you can see how your code will be tested and when you hit _Save + verify_ you can look at its output.
25+
By the way, notice that we use `pytest` for [our Bites](https://codechalleng.es/bites/) too. Under the _TESTS_ tab of each Bite you can see how your code will be tested and when you hit _Save + verify_ you can look at its output.
2626

27-
Lastly if you are serious about writing tests and pytest check out Brian Okken's [Test and Code](http://testandcode.com) podcast and his [Python Testing with pytest](https://pragprog.com/book/bopytest/python-testing-with-pytest) ([our review](https://pybit.es/pytest-book.html)), which goes into much more depth.
27+
Lastly if you are serious about writing tests and `pytest` check out Brian Okken's [Test and Code](http://testandcode.com) podcast and his [Python Testing with pytest](https://pragprog.com/book/bopytest/python-testing-with-pytest) book which goes into much more depth.
2828

29-
## Day N+2: Your Turn: Write a fixture!
29+
## Day N+2: Your Turn: Write a fixture
3030

3131
You wrote some test code? Good, hope that felt good. I know it does because with a set of tests you have more confidence to make any changes in the future. Software systems become increasingly complex so it's paramount to have a suite of tests as your project grows to catch any regression bugs.
3232

33-
On the topic of more complex code, one thing I did not cover are pytest fixtures:
33+
On the topic of more complex code, one thing I did not cover are `pytest` fixtures:
3434

3535
> The purpose of test fixtures is to provide a fixed baseline upon which tests can reliably and repeatedly execute. pytest fixtures offer dramatic improvements over the classic xUnit style of setup/teardown functions - [pytest fixtures: explicit, modular, scalable](https://docs.pytest.org/en/latest/fixture.html)
3636
37-
A typical example is a database app that needs to setup and tear down its state before each test. Read through and [pytest fixtures easy example](http://pythontesting.net/framework/pytest/pytest-fixtures-easy-example/) and try to find a use case for the `pytest.fixture` decorator yourself. You can do it!
37+
A typical example is a database app that needs to setup and tear down its state before each test. Read through [the docs](https://docs.pytest.org/en/latest/fixture.html) and/or this article: [`pytest` fixtures easy example](http://pythontesting.net/framework/pytest/pytest-fixtures-easy-example/). Then try to find a use case for the `pytest.fixture` decorator. For example, I used it [for this small DB app](https://realpython.com/blog/python/building-a-simple-web-app-with-bottle-sqlalchemy-twitter-api/#add-tests-with-pytest) (code [here](https://github.com/pybites/pytip/blob/master/tests/test_tips.py)).
3838

39-
Let me give you another example: I used it [for this DB app](https://realpython.com/blog/python/building-a-simple-web-app-with-bottle-sqlalchemy-twitter-api/#add-tests-with-pytest) ([code](https://github.com/pybites/pytip/blob/master/tests/test_tips.py)).
40-
41-
Ready to become a pytest ninja?
39+
Ready to become a `pytest` ninja? You can do it!
4240

4341
### Time to share what you've accomplished!
4442

0 commit comments

Comments
 (0)