Live data from Hacker News

Ask HN: What is your preferred Python 3 testing framework?

news.ycombinator.com

1–10 of 46 posts

Re: Ask HN: What is your preferred Python 3 testing framework?

#2
pytest:

https://docs.pytest.org/en/latest/

The dependency injection for fixtures is somewhat of a magical entity, but overall I've found it's the most efficient way to hammer out good tests on the standard unit/integration test spectrum. The default mode of operation doesn't even require importing pytest: Just write files named ending with `_test.py`, functions starting with `test`, and bare bones assertions. `yield_fixture` works well with the typical mock-and-assert-on python test pattern.

Plenty of plugins out there for more exotic features, like asyncio, parallelization (though test parallelization tends to be much more problematic beyond "run tests at the same time"), output to , etc too.

Re: Ask HN: What is your preferred Python 3 testing framework?

#6
The company I work for uses standard unittest [0] library from Python. This library helps you to test defined functions in your Python program. For each defined function, you can set different cases to test (positive and negative cases). We also use coverage [1] to see code coverage and report. Report is usually reported to HTML because we can check the missing part of code (the flow of our logic program).

[0]: https://docs.python.org/3/library/unittest.html

[1]: https://pypi.python.org/pypi/coverage

Re: Ask HN: What is your preferred Python 3 testing framework?

#7
post #2

pytest: https://docs.pytest.org/en/latest/ The dependency injection for fixtures is somewhat of a magical entity, but overall I've found it's the most efficient way to hammer out good tests on the standard unit/integration test spectrum. The default mode of operation doesn't even require importing pytest: Just write files named ending with `_test.py`, functions starting with `test`, and bare bones assertions. `yield_…

Just an FYI, normal fixtures can use 'yield', there is no need to use 'yield_fixture' anymore

Re: Ask HN: What is your preferred Python 3 testing framework?

#8
post #7
post #2

pytest: https://docs.pytest.org/en/latest/ The dependency injection for fixtures is somewhat of a magical entity, but overall I've found it's the most efficient way to hammer out good tests on the standard unit/integration test spectrum. The default mode of operation doesn't even require importing pytest: Just write files named ending with `_test.py`, functions starting with `test`, and bare bones assertions. `yield_…

Just an FYI, normal fixtures can use 'yield', there is no need to use 'yield_fixture' anymore

Hah, good to know. Maybe I haven't bumped pytest in a while.

Re: Ask HN: What is your preferred Python 3 testing framework?

#9
post #2

pytest: https://docs.pytest.org/en/latest/ The dependency injection for fixtures is somewhat of a magical entity, but overall I've found it's the most efficient way to hammer out good tests on the standard unit/integration test spectrum. The default mode of operation doesn't even require importing pytest: Just write files named ending with `_test.py`, functions starting with `test`, and bare bones assertions. `yield_…

Pretty much anybody with big modern project i know in the industry is using pytest.

It make the barrier of entry of writting tests much lower. Given how annoying it is to write test, i'd say making it even a tiny bit easier is a win.

Plus fixtures scale better than tearUp and down.

Re: Ask HN: What is your preferred Python 3 testing framework?

#10
post #2

pytest: https://docs.pytest.org/en/latest/ The dependency injection for fixtures is somewhat of a magical entity, but overall I've found it's the most efficient way to hammer out good tests on the standard unit/integration test spectrum. The default mode of operation doesn't even require importing pytest: Just write files named ending with `_test.py`, functions starting with `test`, and bare bones assertions. `yield_…

My favorite feature of pytest is pytest.mark.parametrize, which makes it easy to do table driven testing.
Post reply on HN