CleanCut / green

Green is a clean, colorful, fast python test runner.
MIT License
793 stars 75 forks source link

Running files containing uniitest classes each one in a subprocess #187

Closed wolfc01 closed 6 years ago

wolfc01 commented 6 years ago

Hello,

i want to run the following test skeleton using green, but issuing green test.py fails.

class Test(unittest.TestCase):
  """test """

  def test_1(self):
    """a test"""

p = os.fork()
if p==0: #child
  unittest.main()
else:#parent
  pid, res = os.waitpid(p, 0)
  assert(res==0)

unfortunately for some reasons the fork is required here....

Bets regards Carl.

CleanCut commented 6 years ago

Hehe, it actually "works" for me (after adding needed imports), though you end up with two copies of green running (naturally, since you forked at the module level which is executed upon import), and four copies of your test module running. Green always imports at least once in a master process (which causes the master process to fork) and a second time in a worker process (which causes the worker process to fork) which each fork of the master process spawns.

I'm afraid that if you really need to fork in your test code, green simply won't work well for you. I would be very surprised if there is any test runner that would work out of the box. I think your best option is to control your execution flow manually. Basically, python test.py and what you have already.