Is it possible to break a long function name across multiple lines?

后端 未结 7 1128
南旧
南旧 2021-02-04 23:02

Our development team uses a PEP8 linter which requires a maximum line length of 80 characters.

When I\'m writing unit tests in python, I like to have

7条回答
  •  清歌不尽
    2021-02-04 23:37

    The shorter function name solution has a lot of merit. Think about what is really needed in your actual function name and what is supplied already.

    test_that_client_event_listener_receives_connection_refused_error_without_server(self):
    

    Surely you already know it's a test when you run it? Do you really need to use underscores? are words like 'that' really required for the name to be understood? would camel case be just as readable? how about the first example below as a rewriting of the above (character count = 79): Accepting a convention to use abbreviations for a small collection of common words is even more effective, e.g. Connection = Conn, Error = Err. When using abbreviations you have to be mindful of the context and only use them when there is no possiblity of confusion - Second example below. If you accept that there's no actual need to mention the client as the test subject in the method name as that information is in the class name then the third example may be appropriate. (54) characters.

    ClientEventListenerReceivesConnectionRefusedErrorWithoutServer(self):

    ClientEventListenerReceivesConnRefusedErrWithoutServer(self):

    EventListenerReceiveConnRefusedErrWithoutServer(self):

    I'd also agree with the the suggestion from B Rad C "use descriptive name as the msg kwarg arg in in a self.assert" You should only be interested in seeing output from failed tests when the testsuite is run. Verification that you have all the necessary tests written shouldn't depend on having the method names so detailed.

    P.S. I'd probably also remove 'WithoutServer' as superfluous as well. Shouldn't the client event handler receive the event in the case that the server isn't contactable for any reason? (although tbh I'd think that it would be better that if they client can't connect to a server it receives some sort of 'connection unavailable' , connection refused suggests that the server can be found but refuses the connection itself.)

提交回复
热议问题