from __future__ import (absolute_import, division, print_function,
                        with_statement)

import sys

from tornado.ioloop import IOLoop
from tornado.testing import AsyncHTTPTestCase as TornadoAsyncHTTPTestCase

import pytest


class AsyncHTTPTestCase(TornadoAsyncHTTPTestCase):

    ARGV = []
    SERVICE = None

    @pytest.fixture(autouse=True)
    def set_commandline(self, monkeypatch):
        monkeypatch.setattr(sys, 'argv', self.ARGV)

    def get_new_ioloop(self):
        return IOLoop.instance()

    def get_app(self):
        service = self.SERVICE()
        service.initialize_logging()
        return service.get_app()

from __future__ import (absolute_import, division, print_function,
                        with_statement)

import sys

from tornado.ioloop import IOLoop
from tornado.testing import AsyncHTTPTestCase as TornadoAsyncHTTPTestCase

import pytest


class AsyncHTTPTestCase(TornadoAsyncHTTPTestCase):

    ARGV = []
    SERVICE = None

    @pytest.fixture(autouse=True)
    def set_commandline(self, monkeypatch):
        monkeypatch.setattr(sys, 'argv', ['pytest'] + self.ARGV)

    def get_new_ioloop(self):
        return IOLoop.instance()

    def get_app(self):
        service = self.SERVICE()
        service.initialize_logging()
        return service.get_app()

Add pytest to mocked sys.argv
Add pytest to mocked sys.argv

If you want to use this for integration tests, the ARGV variable only
has to contain the arguments. The first argument usually is the script
name and is not read by tornado at all.

  from __future__ import (absolute_import, division, print_function,
                          with_statement)
  
  import sys
  
  from tornado.ioloop import IOLoop
  from tornado.testing import AsyncHTTPTestCase as TornadoAsyncHTTPTestCase
  
  import pytest
  
  
  class AsyncHTTPTestCase(TornadoAsyncHTTPTestCase):
  
      ARGV = []
      SERVICE = None
  
      @pytest.fixture(autouse=True)
      def set_commandline(self, monkeypatch):
-         monkeypatch.setattr(sys, 'argv', self.ARGV)
+         monkeypatch.setattr(sys, 'argv', ['pytest'] + self.ARGV)
  
      def get_new_ioloop(self):
          return IOLoop.instance()
  
      def get_app(self):
          service = self.SERVICE()
          service.initialize_logging()
          return service.get_app()
  
Add pytest to mocked sys.argv
## Code Before:
from __future__ import (absolute_import, division, print_function,
                        with_statement)

import sys

from tornado.ioloop import IOLoop
from tornado.testing import AsyncHTTPTestCase as TornadoAsyncHTTPTestCase

import pytest


class AsyncHTTPTestCase(TornadoAsyncHTTPTestCase):

    ARGV = []
    SERVICE = None

    @pytest.fixture(autouse=True)
    def set_commandline(self, monkeypatch):
        monkeypatch.setattr(sys, 'argv', self.ARGV)

    def get_new_ioloop(self):
        return IOLoop.instance()

    def get_app(self):
        service = self.SERVICE()
        service.initialize_logging()
        return service.get_app()

## Instruction:
Add pytest to mocked sys.argv
## Code After:
from __future__ import (absolute_import, division, print_function,
                        with_statement)

import sys

from tornado.ioloop import IOLoop
from tornado.testing import AsyncHTTPTestCase as TornadoAsyncHTTPTestCase

import pytest


class AsyncHTTPTestCase(TornadoAsyncHTTPTestCase):

    ARGV = []
    SERVICE = None

    @pytest.fixture(autouse=True)
    def set_commandline(self, monkeypatch):
        monkeypatch.setattr(sys, 'argv', ['pytest'] + self.ARGV)

    def get_new_ioloop(self):
        return IOLoop.instance()

    def get_app(self):
        service = self.SERVICE()
        service.initialize_logging()
        return service.get_app()
