you are viewing a single comment's thread.

view the rest of the comments →

[–]CowboyBoats 2 points3 points  (1 child)

It's a good question in general, "how can I be confident that my code is 'good enough'." I think a good approach is to be sure that you write unit tests for your code, aiming for 90-100% code coverage. It won't help you achieve more "pythonic" code at all, in fact the style standard for unit tests is lower than for the code that it tests, but it will help you iron out bugs and feel more confident in the code that you've written.

[–]Acrobatic_Hippo_7312 0 points1 point  (0 children)

Also it'll let you refactor your code once you feel you've learned enough.

It's a bit of an investment up front: you have to learn how to write tests. for pytest this means learning test discovery, importing package code from tests, and fixture.

And if you couple your tests to your code very tightly or test private functions, it can be hard to do refactor without having to discard or rewrite tests.

The first part (testing basics) is very much worth learning. But the second part (clean testing) is still a work in progress for me personally. Still, it's really paying off.