How best to initialize in unit tests?

Skip Montanaro skip.montanaro at gmail.com
Wed Oct 4 11:23:48 EDT 2017


On Wed, Oct 4, 2017 at 9:53 AM, Steve D'Aprano
<steve+python at pearwood.info> wrote:
> On Thu, 5 Oct 2017 12:07 am, Skip Montanaro wrote:
>
>> Suppose you want to test a package (in the general sense of the word,
>> not necessarily a Python package).
>
> I'm... not sure I understand. Given that we're discussing Python, in a Python
> group, what are senses are relevant?

I have to test an entire application, which involves at least one
package, unit tests and doctests. I suppose I should have used the
word "application." My apology.

>
>> You probably have specific unit
>> tests, maybe some doctests scattered around in doc strings. Further,
>> suppose that package requires you call an initialize function of some
>> sort. Where does that go?
>
> Ew. Sounds like a badly designed package.

I will refer interested readers to the nose documentation:

https://nose.readthedocs.io/en/latest/doc_tests/test_init_plugin/init_plugin.html

where the author writes, "Many applications, especially those using
web frameworks like Pylons or Django, can’t be tested without first
being configured or otherwise initialized."

My system, while not a web framework, does still require the caller of
the client libraries (both Python and R, as it happens) to tell the
system what server to contact. In the case of my test scenario, that
is a Flask server on the local host with a SQLite database behind it,
as opposed to a Flask server somewhere out on the network. (I actually
attempt to test both client and server at the same time.)

Skip



More information about the Python-list mailing list