For most projects you should write automated tests. You should if you value your time anyway.
Much better to catch a bug locally from the tests than getting a call at 2:00 in the morning and fix it then.
Often I find myself saving time when I put time in to write tests. It may or may not take longer to implement what I'm building, but I (and others) will almost definitely save time maintaining it.
Reference: https://kentcdodds.com/blog/write-tests by Kent C. Dodds
Projects all over the Internet have switched from unittest or nose to pytest, including Mozilla and Dropbox.
Why?!
Offers powerful features such as:
assert
rewritingFeature | Pytest | Unittest | Winner |
---|---|---|---|
Installation | Third Party | Built in | Unittest |
Basic Infra | Can be only a function | Inheritance | Pytest |
Basic Assertion | Builtin assert | TestCase instance methods | Pytest |
Flat is better than nested | Function (1 level) | Method (2 level) | Pytest |
Can run each other test | Can run unittest tests | Can't pytest test | Pytest |
Test Result on console | Error Highlight, code snippet | Only line error, no highlight | Pytest |
Multi param test | Yes, parametrize, keep flat | Yes, sub-test, increase nesting | Pytest |
Test setup | fixture: module, session, function | Template Method: setup, tearDown | Pytest |
Name Refactoring | poor, because of name conventions | rich, regular object orientation | Unittest |
Running Failed Tests | built in (--lf, --ff) | your own =,( | Pytest |
Marks | built in | your own =,( | Pytest |
Ref: https://github.com/renzon/pytest-vs-unittest
All of the tests are kept in tests and separate from the package source files in src. This isn’t a requirement of pytest, but it’s a best practice.
Brian Okken
I like to keep functional and unit tests separate because functional tests should only break if we are intentionally changing functionality of the system, whereas unit tests could break during a refactoring or an implementation change.
Brian Okken
or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Syncing