Tests for internal functionality
In https://github.com/python/cpython/pull/6541 , I was requested to add tests for an internal C function. As I wrote in https://github.com/python/cpython/pull/6541#issuecomment-445514807 , it's not clear from the codebase 1) where tests for internal (as opposed to public) functionality should be located * I only ran across very few tests for private functionality and they were located alongside the public tests. See e.g. https://github.com/python/cpython/pull/12140 -- site._getuserbase is a private function. 2) what spec one should test against since there's no official docs for internal functionality That time, they let it slide, but of course this is not something to make a habit of. It still bothers me that I left unfinished business there. Any thoughts? -- Regards, Ivan
On 3/16/2019 3:10 AM, Ivan Pozdeev via Python-Dev wrote:
In https://github.com/python/cpython/pull/6541 , I was requested to add tests for an internal C function.
As I wrote in https://github.com/python/cpython/pull/6541#issuecomment-445514807 , it's not clear from the codebase
1) where tests for internal (as opposed to public) functionality should be located
In the same file where they would be if public, which is what you seemed to find. Label somehow, such as 'class InternalsTest(TestCase):' or 'test__private' (with double __ indicating test of _private).
* I only ran across very few tests for private functionality and they were located alongside the public tests. See e.g. https://github.com/python/cpython/pull/12140 -- site._getuserbase is a private function.
2) what spec one should test against since there's no official docs for internal functionality
Is there an informal spec in the form of docstring or comments? Besides that, test against current behavior. The main purpose of retro-testing is to detect *unintended* changes of behavior (regressions).
That time, they let it slide, but of course this is not something to make a habit of. It still bothers me that I left unfinished business there. Any thoughts?
-- Terry Jan Reedy
On Sun, 17 Mar 2019 at 07:27, Terry Reedy
On 3/16/2019 3:10 AM, Ivan Pozdeev via Python-Dev wrote:
In https://github.com/python/cpython/pull/6541 , I was requested to add tests for an internal C function.
As I wrote in https://github.com/python/cpython/pull/6541#issuecomment-445514807 , it's not clear from the codebase
1) where tests for internal (as opposed to public) functionality should be located
In the same file where they would be if public, which is what you seemed to find. Label somehow, such as 'class InternalsTest(TestCase):' or 'test__private' (with double __ indicating test of _private).
A belated follow-up here: in most cases, such tests should be marked with https://docs.python.org/3/library/test.html#test.support.cpython_only, so they get skipped automatically when the test suite is run against another implementation. Cheers, Nick. -- Nick Coghlan | ncoghlan@gmail.com | Brisbane, Australia
participants (3)
-
Ivan Pozdeev
-
Nick Coghlan
-
Terry Reedy