Skip to content

Use set_log_path hook,but only create log file, nothing in it. #5428

Closed

Description

@trimQiu

Using the 'set_log_path' hook on pytest 4.6.2 (Python 3.6.5) creates log files but does not write anything to them.

In conftest.py I write like #4707

@pytest.hookimpl(hookwrapper=True,tryfirst=True)
def pytest_runtest_setup(item):
    config=item.config
    logging_plugin=config.pluginmanager.get_plugin("logging-plugin")
    full_fname=os.path.join("Report",item._request.node.name+".log")
    logging_plugin.set_log_path(full_fname)
    yield

After running the pytest command, there are some log files in the "Report" folder. But size of all log files is 0. My test code is like this:

def test_ok1():
	logging.info("ok1")
	
def test_ok2():
	logging.info("ok2")

Activity

  1. added
    plugin: logging
    type: question
    on Jun 25, 2019
  2. Zac-HD commented on Jun 25, 2019

    @Zac-HD
    Member

    Are you sure that logs are being emitted from those tests? What happens if you don't configure it to log to a file?

    It looks to me like you need to (a) use the caplog fixture, and (b) configure it to capture logging levels below WARNING (the default).

  3. cameronhudson8 commented on Jul 24, 2019

    @cameronhudson8

    I'm using the --log-file=./myfile.log argument, and I have the same problem: A log file is created, but it's blank. I have failing tests, so I doubt that an insufficient log level is to blame.

  4. The-Compiler commented on Jul 24, 2019

    @The-Compiler
    Member

    @cameronhudson8 Your issue is unrelated to this (see #5659).

  5. Zac-HD commented on Sep 13, 2019

    @Zac-HD
    Member

    Closing as stale.

  6. illeatmyhat commented on May 19, 2025

    @illeatmyhat

    I had the same issue and it was just because I needed to set the log_level in my pyproject.toml to "INFO"
    Unfortunately it doesn't capture everything that PyCharm captures in the console. I need to be able to see stdout and stderr too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    plugin: loggingtype: question

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions