6

What is the PEP8 correct way for long method's name? I have a unit test with a self-describing method:

def success_if_buying_price_item_when_participating_and_progression_is_100_percent(self):

But unfortunately this (too long?) method reaches the 80 characters line limit.

Should I rename it and add a description in code or there is an other way?

bagage
  • 1,094
  • 1
  • 21
  • 44
  • You can break lines up as described in this other SO Post. http://stackoverflow.com/questions/2070684/how-can-i-make-my-python-code-stay-under-80-characters-a-line – sealz Nov 14 '13 at 17:59
  • 2
    That name says to me "this method is doing something far too special-purpose. It should be generalized." – zwol Nov 14 '13 at 17:59
  • 12
    "Should I rename it" -- Yes. "add a description in code" -- This is what docstrings are for. – mgilson Nov 14 '13 at 18:04
  • 5
    For the love of whatever it is that you love, please rename it – codegeek Nov 14 '13 at 18:09
  • 4
    Ok, I upvoted anyone saying you should rename it because it was such a fun, BUT this is a unittest method, and I've written _way_ longer unittest method names. That's part of the fun too – bruno desthuilliers Nov 14 '13 at 20:48
  • This is the reason why I asked for this specific case... but since every one seems to agree, I'm looking for a new name :) – bagage Nov 15 '13 at 15:41
  • 1
    im curious to what name you came up with. If you did go with a shorter name, you would have multiple tests with almost similar and conflicting names. In the case of test failures and looking at the generated report, how do you quickly know what test failed and why? – Naveen Jul 25 '18 at 15:35
  • I did not rename it because test names are often used as-is in report as you stated. And it felt worthless to try to fix that non-issue which is very test specific anyway... – bagage Jul 25 '18 at 19:03
  • Also try adding description in the assertion code, like `self.assertTrue(condition, "description comes here")`. This will allow having some explanation in the CI pipeline logs. – amertkara Jan 08 '21 at 15:35

1 Answers1

25

Should I rename it and add a description in code or there is an other way?

Yes, rename it and add a description. This code is dangerous, one could fall from its chair while another could have a heart attack. Please, rename that ASAP, you don't want to feel responsible.

Maxime Chéramy
  • 17,761
  • 8
  • 54
  • 75