On Fri, Sep 24, 2021 at 07:45:41PM -0700, Christopher Barker wrote:

> 1) this should be part of a test framework, not something built in to
> exceptions. Pytest has shown that it can be done without any language
> changes.

Pytest needs to take heroic measures in an import hook to re-write your
assertions to do what it does:

http://pybites.blogspot.com/2011/07/behind-scenes-of-pytests-new-assertion.html


Maybe a language change, with a public API for assertions, would make it 
much easier and less hacky for test frameworks to do what Pytest does.

It wouldn't be the first time that Python added features to the language 
to make it easier for third-party libraries.

Also, Pytest only supports CPython and PyPy.

https://pytest.org/en/6.2.x/getting-started.html

I know that Jython and IronPython aren't getting all the love that maybe 
they should be getting (migration to 3.x seems to be pretty slow), but 
it would be nice if better assertions was a language feature rather than 
requiring heroic import hook and AST hacks to work.


> 2) there are a lot of things in Pytest that are very useful. 

Will they be less useful if Python gives better diagnostics on assertion 
failures?


> And a lot of problems with unittest.

Such as?

The only really unpleasant part of unittest is having to remember the 
spellings of all the various `self.assertSpam...` methods. Otherwise, 
it's a pretty nice framework.

If assertions were better, perhaps we could fix that.

On the other hand, I personally regularly use plain old assert in my 
unit tests, to distinguish between internal checks of the test logic, 
versus actual unit tests.

Tests are code too, and can be buggy. I think it is important that test 
code includes assertions that refer to the test code itself.


-- 
Steve
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/A7SKAQBCJU3TW4VI5LESKUJPPT7NCSG2/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to