from magicbus.compat import ntob
import os
thismodule = os.path.abspath(__file__)
import sys

from magicbus import bus
from magicbus.plugins import opsys
from magicbus.test import Process, WebAdapter, WebService
from magicbus.test import WebHandler

from magicbus.plugins import loggers
loggers.StdoutLogger(bus).subscribe()

pidfile = opsys.PIDFile(bus, os.path.join(thismodule + '.pid'))


class Handler(WebHandler):

    bus = bus

    def do_GET(self):
        if self.path == '/':
            self.respond('Hello World')
        elif self.path == '/pid':
            self.respond(str(os.getpid()))
        elif self.path == '/exit':
            self.respond('ok')
            self.bus.transition('EXITED')
        else:
            self.respond(status=404)
service = WebService(handler_class=Handler)


def test_daemonize():
    if os.name not in ['posix']:
        return 'skipped (not on posix)'

    # Spawn the process and wait, when this returns, the original process
    # is finished.  If it daemonized properly, we should still be able
    # to access pages.
    p = Process([sys.executable, thismodule, 'daemonize'])
    p.start()
    pidfile.wait()
    try:
        # Just get the pid of the daemonization process.
        resp = service.do_GET('/pid')
        assert resp.status == 200
        page_pid = int(resp.read())
        with open(pidfile.pidfile, 'rb') as pid_file:
            actual_pid = pid_file.read()
        assert ntob(str(page_pid)) == actual_pid
    finally:
        # Shut down the spawned process
        service.do_GET('/exit')
    pidfile.join()

    # Wait until here to test the exit code because we want to ensure
    # that we wait for the daemon to finish running before we fail.
    p.process.wait()
    assert p.process.returncode == 0, (
        'Daemonized parent process returned exit code {rc!s}.'.
        format(rc=p.process.returncode)
    )


if __name__ == '__main__':
    mode = sys.argv[1]
    if mode == 'daemonize':
        opsys.Daemonizer(bus).subscribe()
    pidfile.subscribe()
    WebAdapter(bus, service).subscribe()
    bus.transition('RUN')
    bus.block()

@@ -87,16 +87,31 @@
 rt sys%0A%0A
+import pytest%0A%0A
 from mag
@@ -820,45 +820,36 @@
 )%0A%0A%0A
-def test_daemonize():%0A    if 
+@pytest.mark.skipif(
 os.name 
 not 
@@ -848,66 +848,64 @@
 ame 
-not in %5B'posix'%5D:%0A        return 'skipped (not on posix)'%0A
+!= 'posix', reason='not on POSIX')%0Adef test_daemonize():
 %0A   

Use a proper skipif in `test_opsys.test_daemonize`