Code Monkey home page Code Monkey logo

Comments (6)

jenisys avatar jenisys commented on September 26, 2024 1

I assume that you are using the pretty formatter ?!?
In this case, the —no-color option causes a different behavior in the pretty formatter. In colored mode, it writes the steps twice:

  • Once before it is executed (in gray)
  • And another time after the step has finished and the result is known
  • It overwrites how much lines this step needs

If you do not capture the output, behave is not aware of any printed output.
Therefore, such output lines are overwritten.

You seem to need a feature, like:

  • show-always-captured-output (after the step is executed or after scenario is executed)
  • You should be able to provide the basic functionality for this by using an after_scenario() hook that uses:
def after_scenario(ctx, scenario):
   # PRECONDITION: Captured output is stored only if junit reporter is enabled (for passing scenarios).
   report = scenario.captured.make_report()
   if report:
      print(report)
  • You could do the same with an after_step() hook, that output the ctx.scenario.captured.make_report(). To simplify things, you should probably reset the captured output after each step.

from behave.

jenisys avatar jenisys commented on September 26, 2024 1

Sorry, I disagree.
That is as if you blame your car manufacturer that you are in a traffic jam.

If you use -no-capture, etc. the output/log-output is outside of behave.
Therefore, behave can not do anything about it. That is a deficit of the pretty formatter and maybe unexpected for you and others. But you are free to:

  • choose another formatter
  • use the pretty formatter without color
  • capture the output/log-output and
  • perform something like show-always-captured-output with captured-output/log-output (where currently only rudimentary support exists)
  • use logging to a file without capturing it (to inspect it later-on)

OTHERWISE:
If you have a better, robust solution how the pretty formatter should behave in colored mode, provide a pull-request.

from behave.

jenisys avatar jenisys commented on September 26, 2024

MAYBE RELATED FIX:

  • #1120 — INTEGRATED INTO: behave v1.2.7.dev4

Therefore, try the tip of the repository or behave v1.2.7.dev4 or newer (installed from the Git repository)

NOTE:
By shortly looking over the implementation, —no-color option should not have any effect on logging output.

from behave.

rittneje avatar rittneje commented on September 26, 2024

This bug isn’t specific to logging. It seems that if a step writes to stdout (and it isn’t captured), then the last line of output is lost. A logger configured as above is one way to hit this. A plain old print statement is another.

My assumption is it gets overwritten when behave tries to change the step text to green.

from behave.

rittneje avatar rittneje commented on September 26, 2024

@jenisys This is clearly a bug in behave caused by two of its features (--color and --no-capture) interacting poorly. It's not a feature request, and I'm not "mistaken".

To fix this bug, the "pretty print" logic or whatever needs to be fixed to detect this situation and respond appropriately.

from behave.

rittneje avatar rittneje commented on September 26, 2024

No, it's as if turning on the windshield wiper caused the radio to stop working, and my car manufacturer refused to admit there was a problem.

The bug comes from here, where it uses a special ANSI code to "rewind" the terminal to the previous line.

self.stream.write(up(lines))

I don't use ANSI escape sequences, but it seems you should use the DSR escape sequence to get the current offset before writing the step text (orig_offset). Then after the step has executed, save the current offset again (new_offset), use the CUP escape sequence to restore orig_offset, overwrite the step text in green/red, and then restore new_offset. Of course, that will not work properly if stdin is being used for another purpose.

Barring that, you should (1) change the default behavior to disable colors if any output capture is disabled, and (2) amend the documentation for --color to mention this flaw.

from behave.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.