https://pantsbuild.org/ logo
#development
Title
# development
h

hundreds-breakfast-49010

11/27/2019, 12:51 AM
I have a draft PR for hooking up arbitrary Subsystems to receive streaming workunits: https://github.com/pantsbuild/pants/pull/8720
one thing I'm not sure about is what the best way to test this is - this relies on having a Subsystem with a specific method called
recevie_workunits
defined and accessible under a python module name
and I'm not sure how to mock this in a test
h

hundreds-father-404

11/27/2019, 1:38 AM
Could you create a new Subsystem in the test itself? Similar to how you tested workspace by setting up a new rule
☝️ 1
a

aloof-angle-91616

11/27/2019, 4:37 AM
THIS IS SUPER COOL!!!
this is great i would approve it
this streaming workunit handler you've devised seems crazy powerful
super exciting stuff no joke
❤️ 1
i really like configuring it via import path, it feels a lot like the way you configure log4j in java/scala by adding an impl on the classpath
h

hundreds-breakfast-49010

11/27/2019, 6:56 PM
@aloof-angle-91616 thanks for your kind words 🙂
@hundreds-father-404 I had a branch where I tried doing that, and had trouble defining the module path in a way
importlib
would accept
I think my mental model of how python module/package paths works is slightly wrong
h

hundreds-father-404

11/27/2019, 6:59 PM
Ahh yes that would be tricky with importlib. What import name were you using for the option? A more heavy weight alternative is to set something up in internal_repo. We do this for some testing of rules
h

hundreds-breakfast-49010

11/27/2019, 7:00 PM
I tried a few things and couldn't get any to work, let me see if I still have some of that code in a reachable commit
looks like I foolishly didn't commit what I was doing, let me try to recreate it
@hundreds-father-404 https://github.com/gshuflin/pants/commit/b58511c35a5383db36731189c270a734e1f6a146#diff-044ed2cfe78a7c7dd5530d225792dd44R278 <- I'm not sure what the right string is to specify a class defined in the same module as the invocation of
importlib
or if this is even possible in python
h

hundreds-father-404

11/27/2019, 7:24 PM
Note that the namespace when you have the test in
tests/python/pants_test
would be
pants_test.reporting.workunits.Workunit
h

hundreds-breakfast-49010

11/27/2019, 7:27 PM
but that would be for a class
Workunit
defined within the
src
tree, right? what about if I'm creating the Subsystem within the
tests
tree, for test use only?
h

hundreds-father-404

11/27/2019, 7:28 PM
Wait in the code you put up, are you trying to import a subsystem defined in
src
or
tests
? If it’s defined in
src
, then the import starts with
pants
. If the subsystem is defined in
tests
, then the import starts with
pants_test
h

hundreds-breakfast-49010

11/27/2019, 7:38 PM
I'm trying to import something defined in tests, there is no
src
subsystem
h

hundreds-father-404

11/27/2019, 7:39 PM
Then the import should be
pants_test.reporting.workunits.Workunit
if it’s defined in
tests
h

hundreds-breakfast-49010

11/27/2019, 7:41 PM
huh, okay, it does seem to be possible to import your own module in a test
👍 1
I'm not sure why I thought that wouldn't work
but "pants_test.subsystem.test_subsystem.WorkunitSubscriptableSubsystem" will apparently exercise the code path without throwing an exception
do we have a way in general to test that some specific string was logged?
h

hundreds-father-404

11/27/2019, 7:48 PM
TestBase.captured_logging()
👍 1
h

hundreds-breakfast-49010

11/27/2019, 8:46 PM