-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
#7336 make --log-file relative to inifile if it exists #7350
Changes from 4 commits
d5c8ef8
afaacc5
951a639
45d6a10
bd4a57f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
The pytest ``--log-file`` cli or ``log_file`` ini marker is now relative to the configs ``inifile`` directory, as it was always the intention. It was originally introduced as relative to the current working directory unintentionally. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1152,3 +1152,87 @@ def test_bad_log(monkeypatch): | |
) | ||
result = testdir.runpytest() | ||
result.assert_outcomes(passed=1) | ||
|
||
|
||
def test_log_file_is_in_pytest_ini_rootdir(testdir, monkeypatch): | ||
""" | ||
#7336|#7350 - log_file should be relative to the config inifile | ||
""" | ||
testdir.makefile( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need to change, but you can also use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah i got confused as it made a 'tox' file :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably for historical reasons. |
||
".ini", | ||
pytest=""" | ||
[pytest] | ||
log_cli = True | ||
log_cli_level = DEBUG | ||
log_file = logfile.txt | ||
log_file_level = DEBUG | ||
""", | ||
) | ||
sub = testdir.mkdir("sub") | ||
p = testdir.makepyfile( | ||
""" | ||
def test_this(): | ||
import logging | ||
logging.getLogger().info("Normal message") | ||
""" | ||
) | ||
p.move(sub.join(p.basename)) | ||
monkeypatch.chdir(sub.strpath) | ||
testdir.runpytest() | ||
testdir.chdir() | ||
files = set(os.listdir()) | ||
assert {"logfile.txt", "pytest.ini"}.issubset(files) | ||
|
||
|
||
def test_log_file_can_be_specified_to_child_dir(testdir, monkeypatch): | ||
""" | ||
#7336|#7350 - log_file should be relative to the config inifile | ||
""" | ||
testdir.makefile( | ||
".ini", | ||
pytest=""" | ||
[pytest] | ||
log_cli = True | ||
log_cli_level = DEBUG | ||
log_file = sub/logfile.txt | ||
log_file_level = DEBUG | ||
""", | ||
) | ||
sub = testdir.mkdir("sub") | ||
p = testdir.makepyfile( | ||
""" | ||
def test_this(): | ||
pass | ||
""" | ||
) | ||
p.move(sub.join(p.basename)) | ||
monkeypatch.chdir(sub.strpath) | ||
testdir.runpytest() | ||
files = set(os.listdir()) | ||
assert "logfile.txt" in files | ||
assert "pytest.ini" not in files | ||
|
||
|
||
def test_log_file_cli_is_also_relative(testdir, monkeypatch): | ||
""" | ||
#7336|#7350 - log_file should be relative to the config inifile | ||
""" | ||
testdir.makefile( | ||
".ini", | ||
pytest=""" | ||
[pytest] | ||
""", | ||
) | ||
sub = testdir.mkdir("sub") | ||
p = testdir.makepyfile( | ||
""" | ||
def test_this(): | ||
pass | ||
""" | ||
) | ||
p.move(sub.join(p.basename)) | ||
monkeypatch.chdir(sub.strpath) | ||
testdir.runpytest("--log-file", "sub{}logfile.txt".format(os.sep)) | ||
files = set(os.listdir()) | ||
assert "logfile.txt" in files | ||
assert "pytest.ini" not in files |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please make sure to convert
inifile
to apy.path.local
insideif inifile:
below to honor this type annotation.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a PR locally which addresses these issues (by fixing errors after running mypy with pytest-dev/py#232). I'll post it in a bit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
test_inifilename hates such change(s) - investigating; maybe the test should be just updated: