robotframework-robocop icon indicating copy to clipboard operation
robotframework-robocop copied to clipboard

Check of .robocop file during execution

Open matusaurio opened this issue 2 years ago • 1 comments

What happened?

Hello,

Hopefully you can help me with this.

As an example, let's image we have the following tree structure:

workspace -- resources ---- .robocop ---- resources_file.resource -- tests ---- .robocop ---- robot_tests_file.robot

Each path has its own .robocop file because I want to exclude some rules (different ones) depending on the file type (resources or robot files).

So, when I execute robocop from the workspace folder, this is the output:

> robocop -vv resources
No config file found or configuration is empty. Using default configuration
Scanning file: ...

Thus, the .robocop file inside the resources' path is ignored, however when I change directory to resources, works as expected:

> cd resources
> robocop -vv .
Loaded configuration from /home/user/workspace/resources/.robocop
Scanning file: ...

I'm fairly sure this is not an issue, but that's how robocop it's supposed to work, in that case, this report is not a Bug but a Feature request. In any case, it would be great that when calling the robocop command, it also checks the path being verified for .robocop files.

Thanks.

Operating System

Linux (Ubuntu 20.04)

Robocop version

2.0.1

matusaurio avatar Apr 20 '22 13:04 matusaurio

Yes, it's not a bug. Robocop checks current working directory and its parent until it finds either .robocop or pyproject.toml file or reach top of repository (denoted by .git directory existence).

In your first case it starts looking from workspace - and if workspace does not contain .git directory, its parents directories until it finds configuration file.

For feature request it's quite nice to have - although there are some problems we need to solve. First of all our implementation is bit tied with configuration class (which is created at the beginning when loading cli options / config file) -> and there are things that could be problematic to handle if the configuration would change in the middle of execution. For example in your case resources/ directory could contain --reports all where tests/ no reports at all. Those kind of settings change the behaviour of whole execution. We would need most likely to note what kind of settings are loaded and used once (from first configuration file found) and which settings can be overwritten (such as include/exclude rules per directory).

The other problems:

  • if the parent directories also contain configuration files (ie in workspace), should we create completely new config class or rather overwritten some of the parameters with "child" configs? The latter would work same as conftest works in pytest. Given this "parent" config:
    --format <diff than default format>
    --include this-or-that
    
    and "child" config:
    -- exclude them
    
    For directories under "child" configuration we could have either config with custom format, include 'this-or-that' and exclude 'them' or just exclude them (without custom format and include from "parent" config).
  • right now robocop loads config first and then it can be overwritten by cli. It most likely should stay like that - whatever config is set depending on files, it should be ovewritten by cli options.

bhirsz avatar Apr 20 '22 16:04 bhirsz