Testing In Python by Noah Gift & Alfredo Deza

Testing In Python by Noah Gift & Alfredo Deza

Author:Noah Gift & Alfredo Deza [Noah Gift]
Language: eng
Format: epub
Publisher: Pragmatic AI Solutions
Published: 2020-02-26T16:00:00+00:00


Why and when to monkeypatch?

Most of the code that a developer will interact with is already written. There is not that much chance to create large codebases from scratch. The reality is that a lot of large codebases have almost no tests, which is a direct relation with high-complexity code. When writing new code, like a function, for example, if testing is treated as a first-class citizen, at the forefront of producing the function, then it is highly probable that the function will be easier to test. The reason for this is because as you are writing the function, you will think about how to make it easier for yourself when a test gets added.

When testing is not even considered, then expect things to go wild. That small function you produced will grow and grow until it is seven hundred lines of code that no one wants to touch because something always breaks when a change is done. Reason number one to monkeypatch? When a piece of code has dependencies that cannot be passed in as an argument, making it impossible to interact with.

For large pieces of code, I recommend extracting the functionality one needs to interact with and then test that. Do not try to monkeypatch the universe so that you can keep growing the seven hundred line function!



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.