[Tutor] Regarding A minor styling issue in python
Steven D'Aprano
steve at pearwood.info
Sun Mar 25 05:39:02 EDT 2018
On Sat, Mar 24, 2018 at 12:32:33PM -0500, Neerja Narayanappa wrote:
> Hi,
>
> For example, suppose I have a method name “_pen_namespace” and I would
> like to write a test case to check this method, should my function
> name look like
>
> 1. test__pen_namespace_for something
> or
> 2. test_pen_namespance_for_something
Neither. The first is a syntax error, because you have a space in the
name, and the second is confusingly named "namespance".
The rule I use when writing unit tests, is that if I write a test for a
private function, I drop the leading underscore from the test. Having
test__spam
is too easy to mistype, so I just use
test_spam
even if spam is a private method. So in your case, I would write:
test_pen_namespace
if it includes *all* _pen_namespace tests, and if it only includes a
subset, I would probably use names like:
test_pen_namespace_fail_on_condition
test_pen_namespace_fail_on_bad_values
test_pen_namespace_return_value
test_pen_namespace_check_something
and so forth.
--
Steve
More information about the Tutor
mailing list