import sys
from nose.plugins import Plugin
from subprocess import Popen


class WatchPlugin(Plugin):
    """
    Plugin that use watchdog for continuous tests run.
    """
    name = 'watch'
    is_watching = False
    sys = sys

    def call(self, args):
        Popen(args).wait()

    def finalize(self, result):
        argv = list(self.sys.argv)
        argv.remove('--with-watch')
        watchcmd = 'clear && ' + ' '.join(argv)
        call_args = ['watchmedo', 'shell-command', '-c',
            watchcmd, '-R', '-p', '*.py', '.']
        try:
            self.call(call_args)
        except KeyboardInterrupt:
            self.sys.stdout.write('\nStopped\n')


import sys
from nose.plugins import Plugin
from subprocess import Popen


class WatchPlugin(Plugin):
    """
    Plugin that use watchdog for continuous tests run.
    """
    name = 'watch'
    is_watching = False
    sys = sys

    def call(self, args):
        Popen(args).wait()

    def finalize(self, result):
        argv = list(self.sys.argv)
        try:
            argv.remove('--with-watch')
        except ValueError:
            pass
        watchcmd = 'clear && ' + ' '.join(argv)
        call_args = ['watchmedo', 'shell-command', '-c',
            watchcmd, '-R', '-p', '*.py', '.']
        try:
            self.call(call_args)
        except KeyboardInterrupt:
            self.sys.stdout.write('\nStopped\n')

Add try block to argv remove statement
Add try block to argv remove statement

When running nose-watch withing an environment like django-nose argv doesn't contain any arguments to remove.

  import sys
  from nose.plugins import Plugin
  from subprocess import Popen
  
  
  class WatchPlugin(Plugin):
      """
      Plugin that use watchdog for continuous tests run.
      """
      name = 'watch'
      is_watching = False
      sys = sys
  
      def call(self, args):
          Popen(args).wait()
  
      def finalize(self, result):
          argv = list(self.sys.argv)
+         try:
-         argv.remove('--with-watch')
+             argv.remove('--with-watch')
+         except ValueError:
+             pass
          watchcmd = 'clear && ' + ' '.join(argv)
          call_args = ['watchmedo', 'shell-command', '-c',
              watchcmd, '-R', '-p', '*.py', '.']
          try:
              self.call(call_args)
          except KeyboardInterrupt:
              self.sys.stdout.write('\nStopped\n')
  
- 
Add try block to argv remove statement
## Code Before:
import sys
from nose.plugins import Plugin
from subprocess import Popen


class WatchPlugin(Plugin):
    """
    Plugin that use watchdog for continuous tests run.
    """
    name = 'watch'
    is_watching = False
    sys = sys

    def call(self, args):
        Popen(args).wait()

    def finalize(self, result):
        argv = list(self.sys.argv)
        argv.remove('--with-watch')
        watchcmd = 'clear && ' + ' '.join(argv)
        call_args = ['watchmedo', 'shell-command', '-c',
            watchcmd, '-R', '-p', '*.py', '.']
        try:
            self.call(call_args)
        except KeyboardInterrupt:
            self.sys.stdout.write('\nStopped\n')


## Instruction:
Add try block to argv remove statement
## Code After:
import sys
from nose.plugins import Plugin
from subprocess import Popen


class WatchPlugin(Plugin):
    """
    Plugin that use watchdog for continuous tests run.
    """
    name = 'watch'
    is_watching = False
    sys = sys

    def call(self, args):
        Popen(args).wait()

    def finalize(self, result):
        argv = list(self.sys.argv)
        try:
            argv.remove('--with-watch')
        except ValueError:
            pass
        watchcmd = 'clear && ' + ' '.join(argv)
        call_args = ['watchmedo', 'shell-command', '-c',
            watchcmd, '-R', '-p', '*.py', '.']
        try:
            self.call(call_args)
        except KeyboardInterrupt:
            self.sys.stdout.write('\nStopped\n')
