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-11649: Enable flake8 and fix warnings from tests #40

Merged
merged 5 commits into from Aug 28, 2017
Merged

Conversation

timj
Copy link
Member

@timj timj commented Aug 25, 2017

No description provided.

Copy link
Contributor

@r-owen r-owen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fear subprocess.run is not available in Python 2.7. Otherwise looks good (with one minor suggested change).

@@ -426,7 +426,7 @@ def inTestCase(func):
@inTestCase
def assertRaisesLsstCpp(testcase, excClass, callableObj, *args, **kwargs):
warnings.warn("assertRaisesLsstCpp is deprecated; please just use TestCase.assertRaises",
DeprecationWarning)
DeprecationWarning, 2)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use the named argument stacklevel for clarity., e.g. ...DeprecationWarning, stacklevel=2)


[tool:pytest]
addopts = --flake8
flake8-ignore = E133 E226 E228 N802 N803
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a pity this needs to be repeated, but at least it's nearby in the same file. I suggest adding a comment to the copy above saying "duplicated below", so changes are more likely to be propagated

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, although in meas_base that helps a lot because you can get some errors masked per-file in pytest but have them still show up when you run flake8 manually.


class BacktraceTestCase(lsst.utils.tests.TestCase):
def setUp(self):
pass

def test_segfault(self):
if backtrace.isEnabled():
pipe = subprocess.Popen((sys.executable, "tests/backtrace.py"),
output = subprocess.run([sys.executable, os.path.join(ROOT, "backtrace.py")],
stderr=subprocess.PIPE,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thi is a nice change, but the Python 3 subprocess docs claim run was added in Python 3.5, and the 2.7 version of the docs doesn't list it. Unless future provides it, I don't think you can use it yet. If I'm right then consider a TODO note with the improved code for when we drop python 2.7 support.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😭 That's really annoying. I'll see if I can get check_output to work.

* Determine backtrace.py location from location of test file
  so that the test can run from anywhere.
* Ensure that the forked subprocess is closed properly by using
  check_output rather than native Popen.
* Test that the subprocess does correctly fail.
@timj
Copy link
Member Author

timj commented Aug 28, 2017

Having been forced to look again at the run() code I think I prefer the check_output() option since it lets me use an assert to determine that the command really did fail.

@timj
Copy link
Member Author

timj commented Aug 28, 2017

@r-owen I believe I have made all the requested changes.

@timj timj merged commit f29185d into master Aug 28, 2017
@ktlim ktlim deleted the tickets/DM-11649 branch August 25, 2018 05:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants