So I'm creating unit tests for all of my scripts, many of which arent oo, and have main-loop code. I was wondering what the standard is for the location of creating unittest classes in relation to the affected script. Should the unit test be in a separate file which imports the script, and then function-alize the mainloop code? Or can it shoved at the end of the the related script?
The best practice is to have some related functionality bundled in a module. For that module, you create a separate file with unittests. The convention is to name it test_foo.py if your module is foo.py.
Where it sits exactly is not well defined, although a separate directory named test or something similar is common.
And that has nothing to do with the nature of your code. It can be classes or functions, whatever, as long as it's testable. Of course, making it amenable to testing is not always trivial.
Putting unittest classes in the related script itself vs making a separate file