Skip to content

Conversation

nattofriends
Copy link

Takes #326 to its conclusion (there were still some parts that were not lazy). This allows test methods to be lazily read from a test discovery file.

Copy link
Contributor

@asottile asottile left a comment

Choose a reason for hiding this comment

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

what's the motivation for this change? are there any relevant benchmarks (wall time, memory usage, etc.)


stdout, stderr = cmd_output(
'python', '-m', 'testify.test_program', 'discovery_error', cwd='examples',
'python', '-W', 'ignore::RuntimeWarning:runpy:',
Copy link
Contributor

Choose a reason for hiding this comment

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

curious: what's the RuntimeWarning that's happening here -- can we fix the code instead of silencing the warning?

Copy link
Author

Choose a reason for hiding this comment

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

It's RuntimeWarning: 'testify.test_program' found in sys.modules after import of package 'testify', but prior to execution of 'testify.test_program'; this may result in unpredic table behaviour and I wasn't quite sure how to restructure testify itself to get around this issue

T.assert_in('AttributeError: aaaaa!', stderr)
T.assert_in('AttributeError: aaaaa!', stdout)


Copy link
Contributor

Choose a reason for hiding this comment

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

can we split the lint / test fixes into a separate PR?

Copy link
Author

Choose a reason for hiding this comment

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

I can do this once we agree that this change should actually be made to Testify

if self.__name_overrides is None or member.__name__ in self.__name_overrides:
yield member
already_inspected = set()
name_overrides, self.__name_overrides = itertools.tee(self.__name_overrides)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm -1 on this, I don't believe it makes it any more lazy than the left hand side and at a great cost to readability

else:
tests = open(self.filename)

with tests as tests:
Copy link
Contributor

Choose a reason for hiding this comment

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

now this file doesn't get closed in a timely manner -- is this the RuntimeWarning that you silenced? (seems incorrect to me)

Copy link
Author

Choose a reason for hiding this comment

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

It is not, but I can close this file.

for class_path, tests in groupby(tests, lambda test: test[:2]):
methods = [test.method for test in tests]
module, cls = class_path
methods = (test.method for test in tests)
Copy link
Contributor

Choose a reason for hiding this comment

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

given it's already gone through groupby making this into a generator is likely to increase the memory (as it now needs to keep the closure scope alive), and slower because generators

@nattofriends
Copy link
Author

The reason I am making this change is not to make Testify itself faster. I would like to reduce the time associated with importing the code under test (~25s?) when repeatedly running groups of tests which has been, up to now, passed in via --rerun-test-file. I plan on accomplishing this by passing a fifo instead of an ordinary file, through which I would write a list of tests. These changes to Testify make it so that the file is only read line by line, making it possible to use a fifo to feed in more tests after one group of tests is finished.

@asottile
Copy link
Contributor

asottile commented May 1, 2018

ok that makes sense, but there won't be any code reloading so why use a fifo?

@nattofriends
Copy link
Author

Normally testify would exit after each group of tests. I'd like to keep the fifo open and write more tests into the fifo after the first group of tests is done running.

@asottile
Copy link
Contributor

asottile commented May 1, 2018

But why? presumably the usual test workflow is:

  • run some tests
  • change some code
  • run some more tests

with your proposal, the changes won't be propagated so it might as well just be

  • run some tests
  • run some other tests

which might as well just be

  • run both sets of tests

@nattofriends
Copy link
Author

A human would not use this feature; this is for running all tests in parallel.

@asottile
Copy link
Contributor

asottile commented May 1, 2018

curious what this gains over doing something like

split -n5 tests testsplit
ls testsplit* | xargs -n1 -P5 testify ...

fifos seem like an overly-complicated solution to splitting a file and parallelizing test running

@asottile
Copy link
Contributor

asottile commented May 1, 2018

Note that testify used to have a mode similar to what you're describing but was scrapped due to the sheer complexity: #317

@nattofriends
Copy link
Author

Right, so there is enough value to solving this problem that another stab at the problem had even been attempted before. Here, something else is doing all the parallelization, so this change is less complicated from the testify point of view.

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