📚 node [[python how to write test units]]
Fail Fast
When you aren't sure what's going to happen or there's some ambiguity about whether something will work, raise an exception and fail right there and then with an explanation of what went wrong so you can avoid having to dig through fucking tracebacks for 2 hours.
class TestMaintMode:
@pytest.mark.asyncio
async def test_maint_mode(self, bot, aresponses):
# given/prep/arrange
# when/act/do
# then/assert/check
- Establish test class
- Decorator marks test as async
- Define sync function
- These three are the basic structure of how all tests work
Using Pytest
- Create a python file whose name starts with "test_"
- Either import or begin the file with the function or functions you'd like to test
- Define a number of test functions that take the same arguments as the function/s being tested
assert
a call to the function==
a certain value that you know should be true- Try cover all possible cases for the function in your tests
- Go to the working directory for that file
- run the command
pytest
- Pytest will run and tell you how many tests succeeded and how many failed.
📖 stoas
- public document at doc.anagora.org/python-how-to-write-test-units
- video call at meet.jit.si/python-how-to-write-test-units
⥱ context
↑ pushing here
(none)
(none)
↓ pulling this
(none)
(none)
→ forward
(none)
(none)
🔎 full text search for 'python how to write test units'