Skip to content

Commit

Permalink
QE-13274 Enable color output in logs when running in parallel (#364)
Browse files Browse the repository at this point in the history
Currently when running in parallel, the cucu logs html files don't have
color. With this PR, they will.

The main change is in `src/cucu/cli/run.py` and
`src/cucu/formatter/cucu.py`. The rest of the change is to use
`--no-color-output` in tests so that the `STDOUT` won't have color marks
  • Loading branch information
ddl-xin authored Sep 8, 2023
1 parent f54506a commit d86aa3a
Show file tree
Hide file tree
Showing 17 changed files with 30 additions and 29 deletions.
1 change: 0 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ commands:
command: poetry run cucu run features --workers 8 --selenium-remote-url http://localhost:4444 --generate-report --junit junit_results --browser "<< parameters.browser >>"
environment:
COVERAGE_PROCESS_START: pyproject.toml # set to config file
CUCU_COLOR_OUTPUT: false

run_unit_tests: &run_unit_tests
steps:
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project closely adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## 0.163.0
- Change - enable color output in cucu logs when running in parallel

## 0.162.0
- Fix - use absolute path when uploading files using drag and drop

Expand Down
6 changes: 3 additions & 3 deletions features/cli/config.feature
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Feature: Config
And I echo "\{FIZZ\}"
And I echo "\{BUZZ\}"
"""
When I run the command "cucu run {CUCU_RESULTS_DIR}/load/nested/cucurc --results={CUCU_RESULTS_DIR}/nested_cucurc_from_parent_directory_results --env BUZZ=buzz" and save stdout to "STDOUT", stderr to "STDERR" and expect exit code "0"
When I run the command "cucu run {CUCU_RESULTS_DIR}/load/nested/cucurc --results={CUCU_RESULTS_DIR}/nested_cucurc_from_parent_directory_results --env BUZZ=buzz --no-color-output" and save stdout to "STDOUT", stderr to "STDERR" and expect exit code "0"
Then I should see "{STDOUT}" matches the following:
"""
Feature: Feature file that prints some variables
Expand All @@ -59,7 +59,7 @@ Feature: Config
3 steps passed, 0 failed, 0 skipped, 0 undefined
[\s\S]*
"""
When I run the command "cucu run {CUCU_RESULTS_DIR}/load --results={CUCU_RESULTS_DIR}/nested_cucurc_from_top_level_directory_results --env BUZZ=buzz" and save stdout to "STDOUT", stderr to "STDERR" and expect exit code "0"
When I run the command "cucu run {CUCU_RESULTS_DIR}/load --results={CUCU_RESULTS_DIR}/nested_cucurc_from_top_level_directory_results --env BUZZ=buzz --no-color-output" and save stdout to "STDOUT", stderr to "STDERR" and expect exit code "0"
Then I should see "{STDOUT}" matches the following:
"""
Feature: Feature file that prints some variables
Expand Down Expand Up @@ -113,7 +113,7 @@ Feature: Config
And I echo "\{FIZZ\}"
And I echo "\{BUZZ\}"
"""
When I run the command "cucu run {CUCU_RESULTS_DIR}/load_nested_cucurc_with_workers --results={CUCU_RESULTS_DIR}/nested_cucurc_with_workers_results --env BUZZ=buzz --workers 2" and expect exit code "0"
When I run the command "cucu run {CUCU_RESULTS_DIR}/load_nested_cucurc_with_workers --results={CUCU_RESULTS_DIR}/nested_cucurc_with_workers_results --env BUZZ=buzz --workers 2 --no-color-output" and expect exit code "0"
Then I should see the file at "{CUCU_RESULTS_DIR}/nested_cucurc_with_workers_results/Feature file that prints some variables.log" matches the following:
"""
Feature: Feature file that prints some variables
Expand Down
4 changes: 2 additions & 2 deletions features/cli/run.feature
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Feature: Run
"""

Scenario: User can stop the test execution upon the first failure
Given I run the command "cucu run data/features/feature_with_mixed_results.feature --fail-fast --results {CUCU_RESULTS_DIR}/fail_fast_results" and save stdout to "STDOUT", stderr to "STDERR" and expect exit code "1"
Given I run the command "cucu run data/features/feature_with_mixed_results.feature --fail-fast --results {CUCU_RESULTS_DIR}/fail_fast_results --no-color-output" and save stdout to "STDOUT", stderr to "STDERR" and expect exit code "1"
Then I should not see the directory at "{CUCU_RESULTS_DIR}/passing_feature_dry_run_results"
And I should see "{STDOUT}" matches the following
"""
Expand All @@ -44,7 +44,7 @@ Feature: Run
"""

Scenario: User can run a specific scenario by name
Given I run the command "cucu run data/features/feature_with_mixed_results.feature --name 'Scenario that also passes' --results {CUCU_RESULTS_DIR}/run_by_name_results" and save stdout to "STDOUT", stderr to "STDERR" and expect exit code "0"
Given I run the command "cucu run data/features/feature_with_mixed_results.feature --name 'Scenario that also passes' --results {CUCU_RESULTS_DIR}/run_by_name_results --no-color-output" and save stdout to "STDOUT", stderr to "STDERR" and expect exit code "0"
Then I should not see the directory at "{CUCU_RESULTS_DIR}/passing_feature_dry_run_results"
And I should see "{STDOUT}" matches the following
"""
Expand Down
10 changes: 5 additions & 5 deletions features/cli/run_outputs.feature
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Feature: Run outputs
when running with certain flags/feature files.

Scenario: User can --dry-run a passing scenario
Given I run the command "cucu run data/features/feature_with_passing_scenario.feature --dry-run --results {CUCU_RESULTS_DIR}/passing_feature_dry_run_results" and save stdout to "STDOUT", stderr to "STDERR" and expect exit code "0"
Given I run the command "cucu run data/features/feature_with_passing_scenario.feature --dry-run --results {CUCU_RESULTS_DIR}/passing_feature_dry_run_results --no-color-output" and save stdout to "STDOUT", stderr to "STDERR" and expect exit code "0"
Then I should not see the directory at "{CUCU_RESULTS_DIR}/passing_feature_dry_run_results"
And I should see "{STDOUT}" matches the following
"""
Expand All @@ -21,7 +21,7 @@ Feature: Run outputs
And I should see "{STDERR}" is empty

Scenario: User gets expected output when running steps with substeps
Given I run the command "cucu run data/features/scenario_with_substeps.feature --results {CUCU_RESULTS_DIR}/substeps-results" and save stdout to "STDOUT", stderr to "STDERR" and expect exit code "0"
Given I run the command "cucu run data/features/scenario_with_substeps.feature --results {CUCU_RESULTS_DIR}/substeps-results --no-color-output" and save stdout to "STDOUT", stderr to "STDERR" and expect exit code "0"
Then I should see "{STDOUT}" matches the following
"""
[\s\S]*
Expand All @@ -41,7 +41,7 @@ Feature: Run outputs
And I should see "{STDERR}" is empty

Scenario: User gets expected non zero exit code when a scenario fails
Given I run the command "cucu run data/features/feature_with_failing_scenario.feature --results {CUCU_RESULTS_DIR}/failing-scenario-results" and save stdout to "STDOUT", stderr to "STDERR" and expect exit code "1"
Given I run the command "cucu run data/features/feature_with_failing_scenario.feature --results {CUCU_RESULTS_DIR}/failing-scenario-results --no-color-output" and save stdout to "STDOUT", stderr to "STDERR" and expect exit code "1"
Then I should see "{STDOUT}" matches the following
"""
[\s\S]*
Expand All @@ -68,7 +68,7 @@ Feature: Run outputs
"""

Scenario: User can run a scenario with background which uses a step with substeps
Given I run the command "cucu run data/features/feature_with_background_using_substeps.feature --results {CUCU_RESULTS_DIR}/background-with-substeps-results" and save stdout to "STDOUT", stderr to "STDERR" and expect exit code "0"
Given I run the command "cucu run data/features/feature_with_background_using_substeps.feature --results {CUCU_RESULTS_DIR}/background-with-substeps-results --no-color-output" and save stdout to "STDOUT", stderr to "STDERR" and expect exit code "0"
Then I should see "{STDOUT}" matches the following
"""
Feature: Feature with background using substeps
Expand Down Expand Up @@ -99,7 +99,7 @@ Feature: Run outputs
And I should see "{STDERR}" is empty

Scenario: User can run a scenario with various types of output and see the variable values expanded at runtime
Given I run the command "cucu run data/features/feature_with_multilines_and_tables.feature --results {CUCU_RESULTS_DIR}/variable_values_expanded_results" and save stdout to "STDOUT", stderr to "STDERR" and expect exit code "0"
Given I run the command "cucu run data/features/feature_with_multilines_and_tables.feature --results {CUCU_RESULTS_DIR}/variable_values_expanded_results --no-color-output" and save stdout to "STDOUT", stderr to "STDERR" and expect exit code "0"
And I should see "{STDOUT}" matches the following
"""
Feature: Feature with multilines and tables
Expand Down
4 changes: 2 additions & 2 deletions features/cli/run_with_hooks.feature
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Feature: Run with hooks
Given I echo "Hello"
And I echo "World"
"""
Then I run the command "cucu run {CUCU_RESULTS_DIR}/custom_hooks/echo.feature --results {CUCU_RESULTS_DIR}/custom_hooks_results/ -l debug" and save stdout to "STDOUT", stderr to "STDERR" and expect exit code "0"
Then I run the command "cucu run {CUCU_RESULTS_DIR}/custom_hooks/echo.feature --results {CUCU_RESULTS_DIR}/custom_hooks_results/ -l debug --no-color-output" and save stdout to "STDOUT", stderr to "STDERR" and expect exit code "0"
And I should see "{STDOUT}" matches the following
"""
[\s\S]*
Expand Down Expand Up @@ -101,7 +101,7 @@ Feature: Run with hooks
Given I run the following steps after the current scenario-1
And I run the following steps after the current scenario-2
"""
Then I run the command "cucu run {CUCU_RESULTS_DIR}/custom_hooks/echo.feature --results {CUCU_RESULTS_DIR}/custom_hooks_results/ -l debug" and save stdout to "STDOUT", stderr to "STDERR" and expect exit code "0"
Then I run the command "cucu run {CUCU_RESULTS_DIR}/custom_hooks/echo.feature --results {CUCU_RESULTS_DIR}/custom_hooks_results/ -l debug --no-color-output" and save stdout to "STDOUT", stderr to "STDERR" and expect exit code "0"
And I should see "{STDOUT}" matches the following
"""
[\s\S]*
Expand Down
4 changes: 2 additions & 2 deletions features/cli/run_with_logging.feature
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Feature: Run with logging
--logging-level option

Scenario: User gets does not get debug logging by default
Given I run the command "cucu run data/features/feature_with_logging.feature --results {CUCU_RESULTS_DIR}/default-logging-results" and save stdout to "STDOUT" and expect exit code "0"
Given I run the command "cucu run data/features/feature_with_logging.feature --results {CUCU_RESULTS_DIR}/default-logging-results --no-color-output" and save stdout to "STDOUT" and expect exit code "0"
Then I should see "{STDOUT}" matches the following
"""
Feature: Feature with logging
Expand All @@ -22,7 +22,7 @@ Feature: Run with logging
"""

Scenario: User can expose debug logging when they want it
Given I run the command "cucu run data/features/feature_with_logging.feature --logging-level debug --results {CUCU_RESULTS_DIR}/debug-logging-results" and save stdout to "STDOUT" and expect exit code "0"
Given I run the command "cucu run data/features/feature_with_logging.feature --logging-level debug --results {CUCU_RESULTS_DIR}/debug-logging-results --no-color-output" and save stdout to "STDOUT" and expect exit code "0"
Then I should see "{STDOUT}" matches the following
"""
[\s\S]*
Expand Down
4 changes: 2 additions & 2 deletions features/cli/run_with_tags.feature
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Feature: Run with tags
run.

Scenario: User can run a specific feature using a tag
Given I run the command "cucu run data/features/feature_with_tagging.feature --tags '@second' --show-skips --results {CUCU_RESULTS_DIR}/scenario_with_tag_results" and save stdout to "STDOUT", stderr to "STDERR" and expect exit code "0"
Given I run the command "cucu run data/features/feature_with_tagging.feature --tags '@second' --show-skips --results {CUCU_RESULTS_DIR}/scenario_with_tag_results --no-color-output" and save stdout to "STDOUT", stderr to "STDERR" and expect exit code "0"
Then I should see "{STDOUT}" matches the following
"""
@all
Expand All @@ -29,7 +29,7 @@ Feature: Run with tags
And I should see "{STDERR}" is empty

Scenario: User can exclude a specific feature using a tag
Given I run the command "cucu run data/features/feature_with_tagging.feature --tags '~@second' --show-skips --results {CUCU_RESULTS_DIR}/scenario_without_tag_results" and save stdout to "STDOUT", stderr to "STDERR" and expect exit code "0"
Given I run the command "cucu run data/features/feature_with_tagging.feature --tags '~@second' --show-skips --results {CUCU_RESULTS_DIR}/scenario_without_tag_results --no-color-output" and save stdout to "STDOUT", stderr to "STDERR" and expect exit code "0"
Then I should see "{STDOUT}" matches the following
"""
@all
Expand Down
2 changes: 1 addition & 1 deletion features/cli/run_with_thread_dumper.feature
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Feature: Run with thread dumper
get a periodic thread dump which can help debugging issues in CI.

Scenario: User gets a single thread stacktrace dump and cucu exits cleanly
Given I run the command "cucu run data/features/echo.feature --results {CUCU_RESULTS_DIR}/thread_dumper_results --periodic-thread-dumper=15" and save stdout to "STDOUT" and expect exit code "0"
Given I run the command "cucu run data/features/echo.feature --results {CUCU_RESULTS_DIR}/thread_dumper_results --periodic-thread-dumper=15 --no-color-output" and save stdout to "STDOUT" and expect exit code "0"
Then I should see the previous step took less than "10" seconds
And I should see "{STDOUT}" matches the following
"""
Expand Down
2 changes: 1 addition & 1 deletion features/cli/vars.feature
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ Feature: Vars
Scenario: That simply prints a custom variable
Given I echo "\{CUSTOM_VARIABLE\}"
"""
When I run the command "cucu run {CUCU_RESULTS_DIR}/custom_variables/ --results {CUCU_RESULTS_DIR}/custom_variables_results/" and save stdout to "STDOUT", stderr to "STDERR" and expect exit code "0"
When I run the command "cucu run {CUCU_RESULTS_DIR}/custom_variables/ --results {CUCU_RESULTS_DIR}/custom_variables_results/ --no-color-output" and save stdout to "STDOUT", stderr to "STDERR" and expect exit code "0"
# can see a built in variable
Then I should see "{STDOUT}" matches the following
"""
Expand Down
2 changes: 1 addition & 1 deletion features/flow_control/before_retry_handlers.feature
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Feature: Before retry handlers
# the before retry handler will be the one to click and switch to the next tab
Then I wait to see the button "button with child"
"""
Then I run the command "cucu run {CUCU_RESULTS_DIR}/before_retry_handlers --results {CUCU_RESULTS_DIR}/before_retry_handlers_results" and save stdout to "STDOUT", stderr to "STDERR" and expect exit code "0"
Then I run the command "cucu run {CUCU_RESULTS_DIR}/before_retry_handlers --results {CUCU_RESULTS_DIR}/before_retry_handlers_results --no-color-output" and save stdout to "STDOUT", stderr to "STDERR" and expect exit code "0"
And I should see "{STDOUT}" matches the following
"""
Feature: Feature with scenarios using before retry handlers
Expand Down
4 changes: 2 additions & 2 deletions features/flow_control/run_and_measure.feature
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Feature: Run and measure
And I should see the directory at "\{SCENARIO_RESULTS_DIR\}/files/iter-1"
\"\"\"
"""
When I run the command "cucu run {CUCU_RESULTS_DIR}/measuring_following_steps/measuring_feature.feature --results {CUCU_RESULTS_DIR}/measuring_following_steps_results" and save stdout to "STDOUT", stderr to "STDERR" and expect exit code "0"
When I run the command "cucu run {CUCU_RESULTS_DIR}/measuring_following_steps/measuring_feature.feature --results {CUCU_RESULTS_DIR}/measuring_following_steps_results --no-color-output" and save stdout to "STDOUT", stderr to "STDERR" and expect exit code "0"
Then I should see "{STDOUT}" matches the following:
"""
Feature: Feature that measures a set of steps
Expand Down Expand Up @@ -64,7 +64,7 @@ Feature: Run and measure
Then I should see the directory at "\{SCENARIO_RESULTS_DIR\}/files/iter-1"
And I stop the timer "Create and Verify Directory"
"""
When I run the command "cucu run {CUCU_RESULTS_DIR}/measuring_between_steps/measuring_feature.feature --results {CUCU_RESULTS_DIR}/measuring_between_steps_results" and save stdout to "STDOUT", stderr to "STDERR" and expect exit code "0"
When I run the command "cucu run {CUCU_RESULTS_DIR}/measuring_between_steps/measuring_feature.feature --results {CUCU_RESULTS_DIR}/measuring_between_steps_results --no-color-output" and save stdout to "STDOUT", stderr to "STDERR" and expect exit code "0"
Then I should see "{STDOUT}" matches the following:
"""
Feature: Feature that measures a set of steps
Expand Down
4 changes: 2 additions & 2 deletions features/flow_control/run_scenarios_conditionally.feature
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Feature: Run scenarios conditionally
And I delete the file at "./skip_second_scenario.txt" if it exists

Scenario: User can run scenarios conditionally based on presence of a file
Given I run the command "cucu run data/features/feature_skipping_scenarios_by_file_presence.feature --results {CUCU_RESULTS_DIR}/skip_scenarios_conditionally_results" and save stdout to "STDOUT" and expect exit code "0"
Given I run the command "cucu run data/features/feature_skipping_scenarios_by_file_presence.feature --results {CUCU_RESULTS_DIR}/skip_scenarios_conditionally_results --no-color-output" and save stdout to "STDOUT" and expect exit code "0"
Then I should see "{STDOUT}" matches the following
"""
Feature: Feature with skipping scenarios by file presence
Expand All @@ -33,7 +33,7 @@ Feature: Run scenarios conditionally
"""
bananas
"""
And I run the command "cucu run data/features/feature_skipping_scenarios_by_file_presence.feature --results {CUCU_RESULTS_DIR}/skip_first_scenario_results" and save stdout to "STDOUT" and expect exit code "0"
And I run the command "cucu run data/features/feature_skipping_scenarios_by_file_presence.feature --results {CUCU_RESULTS_DIR}/skip_first_scenario_results --no-color-output" and save stdout to "STDOUT" and expect exit code "0"
Then I should see "{STDOUT}" matches the following
"""
Feature: Feature with skipping scenarios by file presence
Expand Down
2 changes: 1 addition & 1 deletion features/os/platform_steps.feature
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Feature: Platform steps
filesystem

Scenario: User can use platform skipping steps to skip tests correctly
Given I run the command "cucu run data/features/feature_with_platform_specific_scenarios.feature --results {CUCU_RESULTS_DIR}/platform_specific_results" and save stdout to "STDOUT" and expect exit code "0"
Given I run the command "cucu run data/features/feature_with_platform_specific_scenarios.feature --results {CUCU_RESULTS_DIR}/platform_specific_results --no-color-output" and save stdout to "STDOUT" and expect exit code "0"
Then I should see "{STDOUT}" matches the following
"""
Feature: Feature with passing scenario
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "cucu"
version = "0.162.0"
version = "0.163.0"
license = "MIT"
description = "Easy BDD web testing"
authors = ["Domino Data Lab <[email protected]>"]
Expand Down
3 changes: 1 addition & 2 deletions src/cucu/cli/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ def behave(

init_page_checks()

if color_output:
os.environ["CUCU_COLOR_OUTPUT"] = str(color_output).lower()
os.environ["CUCU_COLOR_OUTPUT"] = str(color_output).lower()

if headless:
os.environ["CUCU_BROWSER_HEADLESS"] = "True"
Expand Down
2 changes: 1 addition & 1 deletion src/cucu/formatter/cucu.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def __init__(self, stream_opener, config, **kwargs):
self._multiline_indentation = None

color_output = CONFIG["CUCU_COLOR_OUTPUT"]
self.monochrome = not self.stream.isatty() or color_output != "true"
self.monochrome = color_output != "true"

@property
def multiline_indentation(self):
Expand Down

0 comments on commit d86aa3a

Please sign in to comment.