Example #1
0
  def execute(self):
    def is_python_test(target):
      # Note that we ignore PythonTestSuite, because we'll see the PythonTests targets
      # it depends on anyway,so if we don't we'll end up running the tests twice.
      # TODO(benjy): Once we're off the 'build' command we can get rid of python_test_suite,
      # or make it an alias of dependencies().
      return isinstance(target, PythonTests)

    test_targets = list(filter(is_python_test, self.context.targets()))
    if test_targets:
      self.context.release_lock()

      debug = self.get_options().level == 'debug'

      args = [] if self.get_options().no_colors else ['--color', 'yes']
      for options in self.get_options().options + self.get_passthru_args():
        args.extend(safe_shlex_split(options))
      test_builder = PythonTestBuilder(context=self.context,
                                       targets=test_targets,
                                       args=args,
                                       interpreter=self.interpreter,
                                       fast=self.get_options().fast,
                                       debug=debug)
      with self.context.new_workunit(name='run',
                                     labels=[WorkUnit.TOOL, WorkUnit.TEST]) as workunit:
        # pytest uses py.io.terminalwriter for output. That class detects the terminal
        # width and attempts to use all of it. However we capture and indent the console
        # output, leading to weird-looking line wraps. So we trick the detection code
        # into thinking the terminal window is narrower than it is.
        cols = os.environ.get('COLUMNS', 80)
        with environment_as(COLUMNS=str(int(cols) - 30)):
          stdout = workunit.output('stdout') if workunit else None
          stderr = workunit.output('stderr') if workunit else None
          if test_builder.run(stdout=stdout, stderr=stderr):
            raise TaskError()
Example #2
0
  def run_tests(self, targets, args=None, fast=True, debug=False):
    test_builder = PythonTestBuilder(
        self.context(),
        targets, args or [], fast=fast, debug=debug, interpreter=self._cache_current_interpreter())

    with pushd(self.build_root):
      return test_builder.run()
Example #3
0
  def build(self, targets, args, interpreter=None, fast_tests=False, debug=False):
    test_targets = []
    binary_targets = []
    interpreter = interpreter or PythonInterpreter.get()

    for target in targets:
      assert target.is_python, "PythonBuilder can only build PythonTargets, given %s" % str(target)

    # PythonBuilder supports PythonTests and PythonBinaries
    for target in targets:
      if isinstance(target, PythonTests):
        test_targets.append(target)
      elif isinstance(target, PythonBinary):
        binary_targets.append(target)

    rv = PythonTestBuilder(
        test_targets,
        args,
        interpreter=interpreter,
        fast=fast_tests,
        debug=debug).run()
    if rv != 0:
      return rv

    for binary_target in binary_targets:
      rv = PythonBinaryBuilder(
          binary_target,
          self._run_tracker,
          interpreter=interpreter).run()
      if rv != 0:
        return rv

    return 0
Example #4
0
    def execute(self):
        def is_python_test(target):
            # Note that we ignore PythonTestSuite, because we'll see the PythonTests targets
            # it depends on anyway,so if we don't we'll end up running the tests twice.
            # TODO(benjy): Once we're off the 'build' command we can get rid of python_test_suite,
            # or make it an alias of dependencies().
            return isinstance(target, PythonTests)

        test_targets = list(filter(is_python_test, self.context.targets()))
        if test_targets:
            self.context.lock.release()

            # TODO(benjy): Only color on terminals that support it.
            args = ['--color', 'yes']
            # TODO(benjy): A less hacky way to find the log level.
            if self.context.options.log_level == 'debug':
                args.append(
                    '-s'
                )  # Make pytest emit all stdout/stderr, even for successful tests.
            if self.context.options.pytest_run_options:
                for options in self.context.options.pytest_run_options:
                    args.extend(shlex.split(options))
            test_builder = PythonTestBuilder(
                targets=test_targets,
                args=args,
                interpreter=self.interpreter,
                conn_timeout=self.conn_timeout,
                fast=self.context.options.pytest_run_fast)
            with self.context.new_workunit(
                    name='run', labels=[WorkUnit.TOOL,
                                        WorkUnit.TEST]) as workunit:
                # pytest uses py.io.terminalwriter for output. That class detects the terminal
                # width and attempts to use all of it. However we capture and indent the console
                # output, leading to weird-looking line wraps. So we trick the detection code
                # into thinking the terminal window is narrower than it is.
                cols = os.environ.get('COLUMNS', 80)
                with environment_as(COLUMNS=str(int(cols) - 30)):
                    stdout = workunit.output('stdout') if workunit else None
                    stderr = workunit.output('stderr') if workunit else None
                    if test_builder.run(stdout=stdout, stderr=stderr):
                        raise TaskError()
Example #5
0
    def execute(self):
        def is_python_test(target):
            # Note that we ignore PythonTestSuite, because we'll see the PythonTests targets
            # it depends on anyway,so if we don't we'll end up running the tests twice.
            # TODO(benjy): Once we're off the 'build' command we can get rid of python_test_suite,
            # or make it an alias of dependencies().
            return isinstance(target, PythonTests)

        test_targets = list(filter(is_python_test, self.context.targets()))
        if test_targets:
            self.context.release_lock()

            debug = self.get_options().level == 'debug'

            args = ['--color', 'yes'] if self.get_options().colors else []
            for options in self.get_options().options + self.get_passthru_args(
            ):
                args.extend(safe_shlex_split(options))
            test_builder = PythonTestBuilder(context=self.context,
                                             targets=test_targets,
                                             args=args,
                                             interpreter=self.interpreter,
                                             fast=self.get_options().fast,
                                             debug=debug)
            with self.context.new_workunit(
                    name='run', labels=[WorkUnit.TOOL,
                                        WorkUnit.TEST]) as workunit:
                # pytest uses py.io.terminalwriter for output. That class detects the terminal
                # width and attempts to use all of it. However we capture and indent the console
                # output, leading to weird-looking line wraps. So we trick the detection code
                # into thinking the terminal window is narrower than it is.
                cols = os.environ.get('COLUMNS', 80)
                with environment_as(COLUMNS=str(int(cols) - 30)):
                    stdout = workunit.output('stdout') if workunit else None
                    stderr = workunit.output('stderr') if workunit else None
                    if test_builder.run(stdout=stdout, stderr=stderr):
                        raise TaskError()
Example #6
0
  def execute(self):
    def is_python_test(target):
      # Note that we ignore PythonTestSuite, because we'll see the PythonTests targets
      # it depends on anyway,so if we don't we'll end up running the tests twice.
      # TODO(benjy): Once we're off the 'build' command we can get rid of python_test_suite,
      # or make it an alias of dependencies().
      return isinstance(target, PythonTests)

    test_targets = list(filter(is_python_test, self.context.targets()))
    if test_targets:
      self.context.lock.release()

      # TODO(benjy): Only color on terminals that support it.
      args = ['--color', 'yes']
      # TODO(benjy): A less hacky way to find the log level.
      if self.context.options.log_level == 'debug':
        args.append('-s')  # Make pytest emit all stdout/stderr, even for successful tests.
      if self.context.options.pytest_run_options:
        for options in self.context.options.pytest_run_options:
          args.extend(shlex.split(options))
      test_builder = PythonTestBuilder(targets=test_targets,
                                       args=args,
                                       interpreter=self.interpreter,
                                       conn_timeout=self.conn_timeout,
                                       fast=self.context.options.pytest_run_fast)
      with self.context.new_workunit(name='run',
                                     labels=[WorkUnit.TOOL, WorkUnit.TEST]) as workunit:
        # pytest uses py.io.terminalwriter for output. That class detects the terminal
        # width and attempts to use all of it. However we capture and indent the console
        # output, leading to weird-looking line wraps. So we trick the detection code
        # into thinking the terminal window is narrower than it is.
        cols = os.environ.get('COLUMNS', 80)
        with environment_as(COLUMNS=str(int(cols) - 30)):
          stdout = workunit.output('stdout') if workunit else None
          stderr = workunit.output('stderr') if workunit else None
          if test_builder.run(stdout=stdout, stderr=stderr):
            raise TaskError()
Example #7
0
 def run_tests(self, targets, args=None, fast=True, debug=False):
   test_builder = PythonTestBuilder(targets, args or [], fast=fast, debug=debug)
   with pushd(self.build_root):
     return test_builder.run()