r/Python • u/RickSore • Nov 14 '17
Senior Python Programmers, what tricks do you want to impart to us young guns?
Like basic looping, performance improvement, etc.
1.3k
Upvotes
r/Python • u/RickSore • Nov 14 '17
Like basic looping, performance improvement, etc.
9
u/fiddle_n Nov 14 '17
I guess it's because the thread is about senior programmers giving tips and tricks to junior programmers, and writing unit tests isn't a "tip" or a "trick", it's mandatory. If you are a professional junior programmer and you aren't writing unit tests, you are incompetent, end of story.
With that said, there are two tips I would suggest with regards to unit tests:
Write unit tests regardless of what you are doing. Unit tests are mandatory in a professional setting, but even if you are writing the simplest of pet projects you should write them. Unit tests and test-driven development are extremely useful if you want to code something but you are unsure how to start. Starting off with a basic test that captures what you want to achieve will often help point you in the right direction.
Use
pytestinstead ofunittest. Pytest is just so much nicer IMO. There are many benefits, but my fave is that there is so much less boilerplate code involved. It makes it much nicer to write tests when all you need is a top-level function rather than having to write out a class.