I wrote a little tool to dump the environment of a python interpreter: dumpenv
I have only a linux operating system.
Is there a way to test my code on darwin os?
AFAIK running darwin in a docker container is not possible.
Buying hardware is not an option.
You have a few options:
The MacOS license allows you to run a limited number of virtual machines, but only on Mac hardware. I would use Parallels to run fresh copies of different MacOS systems when testing installation. This does not allow you make a 'hackintosh' by trying to boot up MacOS on a non-Apple hardware stack.
Rent a system in the cloud. As an example, MacInCloud will charge you about $20 per month for a system suitable for testing.
Rent hardware. There is a surprisingly robust market for this.
Here is a random recent article on options. Good luck!