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

DM-38062: Allow logging tests to pass even if pytest is changing the root log level #146

Merged
merged 2 commits into from
Feb 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ jobs:
pytest -r a -v -n 3 --open-files --cov=tests --cov=lsst.utils --cov-report=xml --cov-report=term

- name: Upload coverage to codecov
uses: codecov/codecov-action@v2
uses: codecov/codecov-action@v3
with:
file: ./coverage.xml

Expand Down
10 changes: 7 additions & 3 deletions tests/test_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,15 @@ def testLogCommands(self):

child = root.getChild("child")
self.assertEqual(child.getEffectiveLevel(), root.getEffectiveLevel())
child.setLevel(root.DEBUG)

# The root logger could be modified by the test environment.
# We need to pick a level that is different.
child.setLevel(root.getEffectiveLevel() - 5)
self.assertNotEqual(child.getEffectiveLevel(), root.getEffectiveLevel())

def testTraceSetAt(self):
log_name = "lsst.afw"
root_level = logging.getLogger().getEffectiveLevel()
trace_set_at(log_name, 2)
trace2_log = getLogger(f"TRACE2.{log_name}")
trace3_log = getLogger(f"TRACE3.{log_name}")
Expand All @@ -77,8 +81,8 @@ def testTraceSetAt(self):
log_name = "lsst.daf"
child3_log = getLogger("TRACE3.lsst.daf")
child2_log = getLogger("TRACE2.lsst.daf")
self.assertEqual(child3_log.getEffectiveLevel(), logging.WARNING)
self.assertEqual(child2_log.getEffectiveLevel(), logging.WARNING)
self.assertEqual(child3_log.getEffectiveLevel(), root_level)
self.assertEqual(child2_log.getEffectiveLevel(), root_level)
trace_set_at("lsst", 2)
self.assertEqual(child3_log.getEffectiveLevel(), logging.INFO)
self.assertEqual(child2_log.getEffectiveLevel(), logging.DEBUG)
Expand Down