How to break long method name into more than one line?

Roy Smith roy at
Sun Mar 11 20:11:29 CET 2012

In article <mailman.571.1331492028.3037.python-list at>,
 Herman <sorsorday at> wrote:

> I am trying to stick to the rule described in the TDD book that, each
> test method name consists of the method name to be tested, inputs and
> the expected outputs. It takes up a lot of space and my company has a
> rule of limiting 79 characters (or 80) per line. I found that
> def abcdeef\
> dddaaa(self):
>     pass
> does not work, but
> def \
> abcsajfoijfiawifoiwejfoi(self):
>     pass
> works. Is this the only way to do it?

Arrrrrrrrhhhggggg.  If you can't fit a test method name into 79 
characters, you're doing somthing wrong.  Just for fun, I found all the 
test methods in the project I'm working on and sorted them by length.  
Here's the top of the list:

$ find . -name 'test*py' | xargs grep -h 'def *test' | sort | uniq  | 
awk '{print length($0), $0}' | sort -nr
55     def test_update_name_changes_dasherized_name(self):
51     def test_get_followers_with_no_followers(self):
50     def test_update_station_song_adds_false(self):
50     def test_anonymous_get_user_collections(self):
49     def test_wrong_user_update_should_fail(self):
49     def test_login_with_email_and_password(self):
47     def test_unknown_station_returns_404(self):
47     def test_login_failure_with_facebook(self):
47     def test_get_follows_with_no_follows(self):
46     def test_station_by_dasherized_name(self):
46     def test_nonexistent_recent_station(self):
46     def test_new_user_with_display_name(self):
46     def test_auto_connect_with_facebook(self):
46     def test_anonymous_created_stations(self):
45     def test_no_php_fatal_error_in_log(self):
45     def test_get_only_songza_followers(self):
45     def test_anonymous_vote_transition(self):
44     def test_non_ascii_global_station(self):
44     def test_global_station_not_found(self):
44     def test_gallery_create_duplicate(self):
44     def test_anonymous_listen_history(self):

and so on down to the wonderfully terse:

21     def test_x(self):

which I'm assuming actually makes sense in the context of the TestCase 
class it belongs to.  At least I hope it does :-)

The examples above are a reasonable upper limit on the verbosity you 
should be shooting for, IMHO.

More information about the Python-list mailing list