[TIP] patch automatically functions in external library

Chris Jerdonek chris.jerdonek at gmail.com
Wed Aug 22 09:09:04 PDT 2012

On Wed, Aug 22, 2012 at 8:01 AM, andrea crotti
<andrea.crotti.0 at gmail.com> wrote:
> 2012/8/21 Chris Jerdonek <chris.jerdonek at gmail.com>:
>> On Mon, Aug 20, 2012 at 8:18 AM, andrea crotti
>> <andrea.crotti.0 at gmail.com> wrote:
>>> I have one "common" project that contains a lot of code which is useful
>>> from more different projects.
>>> All projects have (hopefully) unit tests, but what I'm worried about now
>>> is that changing a function signature in *common* might make break
>>> something somewhere else.
>> Maybe I'm not understanding the question, but wouldn't proper unit
>> testing of the "different" projects catch breaking changes in
>> "common"?
> Well in general yes, and it's probably true for my projects.  But
> since not everyone is writing unit tests unfortunately if I have a way
> to check for changed signatures maybe I can help with that..

If you don't have control over the other projects and want to maintain
strict backwards compatibility, then I would say the way to check this
would be through usual unit testing of the common project.

Every function that is part of the public API should be tested with
all arguments.  That way if you inadvertently change the signature of
one of your public functions in a backwards incompatible way, at least
one of your unit tests will fail.  Of course, certain signature
changes would be allowed under this approach (e.g. adding a new
keyword argument at the end) and others not (e.g. changing the order
of positional arguments or renaming a keyword argument).  If you don't
want to allow even backwards compatible changes for certain functions,
you could add additional tests for that.

If you don't have full coverage of the common project (and can't),
then yes, there are probably automated ways to check just the function
signature.  If there isn't a solution already out there, maybe you
could use the inspect module to serialize the aspects of the functions
that you care about into a certain form, and then compare against that
in your test runs.


More information about the testing-in-python mailing list