Beispiel #1
0
def register_as(formatter_class, name):
    """
    Register formatter class with given name.

    :param formatter_class:  Formatter class to register.
    :param name:  Name for this formatter (as identifier).
    """
    warnings.warn("Use behave.formatter._registry.register_as() instead.",
                  DeprecationWarning, stacklevel=2)
    _registry.register_as(name, formatter_class)
def register_as(formatter_class, name):
    """
    Register formatter class with given name.

    :param formatter_class:  Formatter class to register.
    :param name:  Name for this formatter (as identifier).
    """
    warnings.warn("Use behave.formatter._registry.register_as() instead.",
                  DeprecationWarning,
                  stacklevel=2)
    _registry.register_as(name, formatter_class)
Beispiel #3
0
 def setup_formats(self):
     """Register more, user-defined formatters by name."""
     if self.more_formatters:
         for name, scoped_class_name in self.more_formatters.items():
             _format_registry.register_as(name, scoped_class_name)
Beispiel #4
0
                "--junit report type for Behave is unsupported in PyCharm. \n "
                "See: https://youtrack.jetbrains.com/issue/PY-14219")
        _bdd_utils.fix_win_drive(command_args[0])
    (base_dir, scenario_names,
     what_to_run) = _bdd_utils.get_what_to_run_by_env(os.environ)

    for scenario_name in scenario_names:
        command_args += ["-n",
                         re.escape(scenario_name)]  # TODO : rewite pythonic

    my_config = configuration.Configuration(command_args=command_args)

    # Temporary workaround to support API changes in 1.2.5
    if version.LooseVersion(behave_version) >= version.LooseVersion("1.2.5"):
        from behave.formatter import _registry
        _registry.register_as("com.intellij.python.null", _Null)
    else:
        from behave.formatter import formatters
        formatters.register_as(_Null, "com.intellij.python.null")

    my_config.format = ["com.intellij.python.null"
                        ]  # To prevent output to stdout
    my_config.reporters = []  # To prevent summary to stdout
    my_config.stdout_capture = False  # For test output
    my_config.stderr_capture = False  # For test output
    features = set()
    for feature in what_to_run:
        if os.path.isfile(feature) or glob.glob(
                os.path.join(feature, "*.feature")
        ):  # File of folder with "features"  provided, load it
            features.add(feature)
Beispiel #5
0
 def setup_formats(self):
     """Register more, user-defined formatters by name."""
     if self.more_formatters:
         for name, scoped_class_name in self.more_formatters.items():
             _format_registry.register_as(name, scoped_class_name)
    if command_args:
        if "--junit" in command_args:
            raise Exception("--junit report type for Behave is unsupported in PyCharm. \n "
            "See: https://youtrack.jetbrains.com/issue/PY-14219")
        _bdd_utils.fix_win_drive(command_args[0])
    (base_dir, scenario_names, what_to_run) = _bdd_utils.get_what_to_run_by_env(os.environ)

    for scenario_name in scenario_names:
        command_args += ["-n", re.escape(scenario_name)]  # TODO : rewite pythonic

    my_config = configuration.Configuration(command_args=command_args)

    # Temporary workaround to support API changes in 1.2.5
    if version.LooseVersion(behave_version) >= version.LooseVersion("1.2.5"):
        from behave.formatter import _registry
        _registry.register_as("com.intellij.python.null",_Null)
    else:
        from behave.formatter import formatters
        formatters.register_as(_Null, "com.intellij.python.null")


    my_config.format = ["com.intellij.python.null"]  # To prevent output to stdout
    my_config.reporters = []  # To prevent summary to stdout
    my_config.stdout_capture = False  # For test output
    my_config.stderr_capture = False  # For test output
    features = set()
    for feature in what_to_run:
        if os.path.isfile(feature) or glob.glob(
                os.path.join(feature, "*.feature")):  # File of folder with "features"  provided, load it
            features.add(feature)
        elif os.path.isdir(feature):
    my_config = configuration.Configuration(command_args=command_args)

    # New version supports 1.2.6 only
    use_old_runner = "PYCHARM_BEHAVE_OLD_RUNNER" in os.environ
    from behave.formatter import _registry

    FORMAT_NAME = "com.jetbrains.pycharm.formatter"
    if use_old_runner:

        class _Null(Formatter):
            """
            Null formater to prevent stdout output
            """
            pass

        _registry.register_as(FORMAT_NAME, _Null)
    else:
        custom_messages = tcmessages.TeamcityServiceMessages()
        # Not safe to import it in old mode
        from teamcity.jb_behave_formatter import TeamcityFormatter

        class TeamcityFormatterWithLocation(TeamcityFormatter):
            def _report_suite_started(self, suite, suite_name):
                location = suite.location
                custom_messages.testSuiteStarted(
                    suite_name,
                    _bdd_utils.get_location(base_dir, location.filename,
                                            location.line))

            def _report_test_started(self, test, test_name):
                location = test.location
    assert loose_version >= version.LooseVersion("1.2.5"), "Version not supported, please upgrade Behave"

    # New version supports 1.2.6 only
    use_old_runner = "PYCHARM_BEHAVE_OLD_RUNNER" in os.environ or loose_version < version.LooseVersion("1.2.6")
    from behave.formatter import _registry

    FORMAT_NAME = "com.jetbrains.pycharm.formatter"
    if use_old_runner:
        class _Null(Formatter):
            """
            Null formater to prevent stdout output
            """
            pass


        _registry.register_as(FORMAT_NAME, _Null)
    else:
        custom_messages = tcmessages.TeamcityServiceMessages()
        # Not safe to import it in old mode
        from teamcity.jb_behave_formatter import TeamcityFormatter


        class TeamcityFormatterWithLocation(TeamcityFormatter):

            def _report_suite_started(self, suite, suite_name):
                location = suite.location
                custom_messages.testSuiteStarted(suite_name,
                                                 _bdd_utils.get_location(base_dir, location.filename, location.line))

            def _report_test_started(self, test, test_name):
                location = test.location
Beispiel #9
0
if __name__ == "__main__":
    from behave.formatter import _registry
    from behave.configuration import Configuration
    from behave.runner import Runner
    from teamcity.jb_behave_formatter import TeamcityFormatter

    _registry.register_as("TeamcityFormatter", TeamcityFormatter)
    configuration = Configuration()
    configuration.format = ["TeamcityFormatter"]
    configuration.stdout_capture = False
    configuration.stderr_capture = False
    Runner(configuration).run()