Skip to content

caplog fails on getting caplog.messages with str.format() log record #3397

@gurobokum

Description

@gurobokum

Description

In dvc we can use logger.info as

logger.info("{} in str.format()", "log")

because of the custom formatter
but caplog uses default LogRecord.getMessage()

if self.args:
      msg = msg % self.args 

and fails in tests on getting caplog.messages

Steps to reproduce

Create a file with content

def test_caplog(caplog):
    import logging
    logger = logging.getLogger()

    with caplog.at_level(logging.INFO):
        logger.info("This shouldn't fail {}", 1)

    assert len(caplog.messages) == 1

Run it

pytest test_caplog

Produces an error like

test_caplog.py:8:                                                                                                                                      
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../../../.pyenv/versions/3.7.6/envs/dvc/lib/python3.7/site-packages/_pytest/logging.py:387: in messages                                                
    return [r.getMessage() for r in self.records]                                                                                                      
../../../.pyenv/versions/3.7.6/envs/dvc/lib/python3.7/site-packages/_pytest/logging.py:387: in <listcomp>                                              
    return [r.getMessage() for r in self.records]   
....
>           msg = msg % self.args                                                                                           
E           TypeError: not all arguments converted during string formatting                                                 
                                                                                                                           
../../../.pyenv/versions/3.7.6/lib/python3.7/logging/__init__.py:369: TypeError

Info

$ dvc --version
0.86.2+002dd8.mod

Metadata

Metadata

Assignees

Labels

bugDid we break something?p1-importantImportant, aka current backlog of things to dotestingRelated to the tests and the testing infrastructure

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions