Skip to content

Conversation

@bluetech
Copy link
Member

These are some simple cleanups to capture. I have more complex changes planned, but will send them separately.

The changes are split into independent commits. One of the commits reorders sections which makes the PR diff not very readable.

bluetech added 4 commits May 26, 2020 00:25
Removing this indirection enables some further clean ups.
With straight code, it is a little easier to understand, and simplify
further.
This is more straightforward and does not require duplicating the
initialization logic.
@bluetech
Copy link
Member Author

There is some problem on Windows. I'll try to figure it out somehow.

Copy link
Member

@RonnyPfannschmidt RonnyPfannschmidt left a comment

Choose a reason for hiding this comment

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

nice refactoring, its indeed a bit big to get nicely in a single reading, i will take another look later today to gauge the details better

overall it looks good, thanks

def __init__(self, in_, out, err) -> None:
self.in_ = in_
self.out = out
self.err = err
Copy link
Member

Choose a reason for hiding this comment

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

its great this logic is gone from the ctor, an we move the outside factory functions to a named constructor
to encapsulate the in/out/err logic

also it looks to me if attrs couldbe used to declare the ctor/non-ctor atributes now

Copy link
Member Author

Choose a reason for hiding this comment

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

attrs might be nice for some classes here. I'll try to remember this for later.

def start(self):
setattr(sys, self.name, self.tmpfile)
self._state = "started"
def set_fixture(self, capture_fixture: "CaptureFixture") -> None:
Copy link
Member

Choose a reason for hiding this comment

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

at first glance i believe that pair might yield nicer code if it was a context manager instead

Copy link
Member Author

Choose a reason for hiding this comment

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

So, it actually was a context manager, but the commits removes it. The reason is that the context manager adds some indirection which makes it more difficult to refactor further (in later PRs).

@pytest.mark.parametrize("use", [True, False])
def test_fdcapture_tmpfile_remains_the_same(tmpfile, use):
if not use:
tmpfile = True
Copy link
Member

Choose a reason for hiding this comment

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

this test looks strange, whats the value of tmpfile?

Copy link
Member Author

Choose a reason for hiding this comment

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

Right, I'm not sure what this was supposed to do either (it's the same in master -- the two parametrization are actually testing the same thing). I added a commit which removes the parametrization.

bluetech added 5 commits May 27, 2020 15:19
Make it easier to read the file in progression, and avoid forward
references for upcoming type annotations.

There is one cycle, CaptureManager <-> CaptureFixture, which is hard to
untangle.

(This commit should be added to `.gitblameignore`).
Since tmpfile is a parameter to SysCapture, it shouldn't assume things
unnecessarily, when there is an alternative.
There are state transitions start/done/suspend/resume and two additional
operations snap/writeorg.

Previously it was not well defined in what order they can be called, and
which operations are idempotent.

Formalize this and enforce using assert checks with informative error
messages if they fail (rather than random AttributeErrors).
This attribute is set in __init__ and not deleted. Other methods do it
already but this one wasn't updated.
The two cases end up doing the same (the tmpfile fixture isn't used
except being truthy).
@bluetech
Copy link
Member Author

The Windows failures are caused by commit "capture: fix invalid inheritance between Capture classes". The commit somehow changes the newlines-mode such that on print("foo"), instead of capturing "foo\n", "foo\r\n" is captured (on Windows).

I've removed the commit now, will resubmit once I have a chance to fix it up.

@bluetech bluetech force-pushed the capture-cleanup-1 branch from 8ba634a to f93e021 Compare May 27, 2020 12:39
@bluetech bluetech merged commit 54b6fe2 into pytest-dev:master May 27, 2020
@bluetech bluetech deleted the capture-cleanup-1 branch June 17, 2020 14:56
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.

2 participants