Repository navigation
Closed
Description
- a detailed description of the bug or suggestion
- output of
pip listfrom the virtual environment you are using - pytest and operating system versions
- minimal example if possible
Detailed description of the bug
My goal is to run pytest, and have the output land in a file. The file is successfully created, but it's empty.
Here are the files that I start with:
.
├── __pycache__
├── requirements.txt
├── test_main.py
└── venv
The only test file, test_main.py, is very simple:
def test_function():
assert False
When I run pytest --log-file=./myfile.log, I see this log output in the terminal:
========================= test session starts =====================
platform linux -- Python 3.7.3, pytest-5.0.1, py-1.8.0, pluggy-0.12.0
rootdir: /home/cameronhudson/Repositories/pytest-log-test
collected 1 item
test_main.py F [100%]
======================= FAILURES =============================
__________________________ test_function ___________________________
def test_function():
> assert False
E assert False
test_main.py:4: AssertionError
=================== 1 failed in 0.02 seconds =======================
The log file is created, but it's empty.
.
├── myfile.log <-- The new file
├── __pycache__
├── requirements.txt
├── test_main.py
└── venv
Output of pip list
Package Version
------------------ -------
atomicwrites 1.3.0
attrs 19.1.0
importlib-metadata 0.18
more-itertools 7.2.0
packaging 19.0
pip 19.0.3
pluggy 0.12.0
py 1.8.0
pyparsing 2.4.0
pytest 5.0.1
setuptools 40.8.0
six 1.12.0
wcwidth 0.1.7
zipp 0.5.2
PyTest and Operating System versions
PyTest: 5.0.1
Operating system: Debian 9
Minimal Example
As above:
test_main.py
def test_function():
assert False
Command used:
pytest --log-file=./myfile.log
Reacted by James Thomas Moon
Metadata
Metadata
Assignees
Labels
No labels
Activity
The-Compiler commentedon Jul 24, 2019
--log-fileis about logging output which happens via theloggingmodule in your tested code. If you want the output in a file, you could use file redirection (pytest > myfile.log) or if you want to see it as well, theteetool (pytest | tee myfile.log).