Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
trimQiu opened this issue Jun 10, 2019 · 4 comments
Closed

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

trimQiu opened this issue Jun 10, 2019 · 4 comments
Labels
plugin: logging related to the logging builtin plugin type: question general question, might be closed after 2 weeks of inactivity

Comments

@trimQiu
Copy link

trimQiu commented Jun 10, 2019

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")
@Zac-HD Zac-HD added plugin: logging related to the logging builtin plugin type: question general question, might be closed after 2 weeks of inactivity labels Jun 25, 2019
@Zac-HD
Copy link
Member

Zac-HD commented Jun 25, 2019

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).

@CameronHudson8
Copy link

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.

@The-Compiler
Copy link
Member

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

@Zac-HD
Copy link
Member

Zac-HD commented Sep 13, 2019

Closing as stale.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
plugin: logging related to the logging builtin plugin type: question general question, might be closed after 2 weeks of inactivity
Projects
None yet
Development

No branches or pull requests

4 participants