Skip to content

"colorized" ignored when called without shell?d #9445

Open
@buhtz

Description

@buhtz

Bug description

Not sure if tis is a bug. So I ask first. I can run pylint on my shell with --output-format=colorized and get the expected nice and fancy output. But when doing this in Python code via subprocess.run() there is no color and also no colorcodes in the output string.

Might it be that the colorized option is ignored by pylint because it can not detected a color supporting terminal?

I tried to do shell=True in subprocess.run() but then pylint do not find any files to lint. This is another problem. But of course having shell=True is not recommended.

Configuration

Not a config file but a unitest


    def test030_pylint(self):
        # Pylint base command
        cmd = [
            'pylint',
            '--output-format=colorized`,
            # Storing results in a pickle file is unnecessary
            '--persistent=n',
            # autodetec number of parallel jobs
            '--jobs=0',
            # Disable scoring  ("Your code has been rated at xx/10")
            '--score=n',
            # PEP8 conform line length (see PyLint Issue #3078)
            f'--max-line-length={PEP8_MAX_LINE_LENGTH}',
            # prevent false-positive no-module-member errors
            '--extension-pkg-whitelist=lxml',
            # List of members which are set dynamically and missed by pylint
            # inference system, and so shouldn't trigger E1101 when accessed.
            '--generated-members=WD_ALIGN_PARAGRAPH,WD_ORIENT,PARAGRAPH',
            # Allowlist variable names
            '--good-names=idx,fp,df',
            # Allow fstrings when logging
            '--disable=logging-fstring-interpolation',
        ]
        # Add py files
        cmd.extend(self.collected_py_files[6:7])

        # subprocess.run(cmd, check=True)
        r = subprocess.run(
            cmd,
            check=False,
            universal_newlines=True,
            capture_output=True)

        print(f'!!!!!!!!!!!!!!!! {r.stdout=}')
        print(f'!!!!!!!!!!!!1!! {r.stderr=}')
        print(f'ÖÖÖÖÖÖÖÖÖÖÖÖÖÖ {r.returncode=}')

        self.assertEqual(0, r.returncode)

Command used

See configuration

Pylint output

Returncode 28

Expected behavior

Nice colors on my terminal.

Pylint version

pylint 3.0.3                                                                                                                  astroid 3.0.2                                                                                                                 Python 3.9.2 (default, Feb 28 2021, 17:03:44)                                                                                 [GCC 10.2.1 20210110]

OS / Environment

Debian GNU Linux 12

Additional dependencies

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions