lazytest

msolli 2025-08-13T07:39:22.478279Z

I have a custom tagged literal that I use everywhere in my Hiccup-producing functions. In my app I include the ns that defines the Var that reads the tagged literal in a central location (`my-app.main`). I need advice for how to deal with this in tests. There is no central ns to include it in there. The only approach I have come up with is to require the ns that defines the Var from a ns that I then include in all my Hiccup-testing ns-es. While this would work, it is not ideal: a) More stuff to type b) I must remember to include it in every ns Any ideas? Anybody have some global-ish stuff that you include more or less everywhere in your test ns-es?

2025-08-13T11:08:10.844599Z

isn't that handled by data_readers.cljc?

msolli 2025-08-13T11:10:58.242609Z

Yes, data_readers.cljc defines the tag and which Var should be invoked with the form. But the Var needs to be read and compiled before the code that uses the tag is read.

msolli 2025-08-13T11:13:10.443469Z

data_readers.cljc is:

{o/tw oiiku.data-readers.interface/tw}
So the namespace that defines oiiku.data-readers.interface/tw must be read before any namespace that uses #o/tw. In my app I make it so that the main entrypoint requires oiiku.data-readers.interface. But the test suite has no such main entrypoint.

2025-08-13T11:49:44.091899Z

oh i thought data_readers loaded those namespaces

2025-08-13T11:52:35.384339Z

i would say that you should require the namespace from every namespace that produces the tagged literals

2025-08-13T11:53:55.951909Z

you can wrap the lazy test entry point in a custom function that you call from the command line and require the necessary namespaces there

msolli 2025-08-13T11:57:58.567769Z

Yeah, that's an idea. I'm using https://github.com/seancorfield/polylith-external-test-runner to run the suite, so I'll have to figure out how to make it invoke my wrapping function instead of, well, whatever it is invoking. 😅.

2025-08-13T11:58:32.268839Z

there's an Ask to vote on, but i doubt rich or alex are at all interested in fixing it

2025-08-13T11:59:19.446999Z

alex's comments about data readers have been negative on slack in the last couple years so it seems like they won't put any effort into fixing this or making it better

msolli 2025-08-13T12:03:42.661109Z

There are probably Good Reasons:tm: for why it is like it is. Given the status quo, I'll have to figure out a way to always load the data reader Vars before the code that uses the tags. The most straight-forward is of course to just require the defining namespace, directly or indirectly, before using any of the tags.

2025-08-13T12:05:53.938429Z

as seen by the jira ticket, they've decided against working on this

2025-08-13T12:06:24.328599Z

yeah it's a bummer

msolli 2025-08-13T12:20:41.605109Z

Well, it's less reliant on magic, so that's good, I guess. Thanks for investigating/rubberducking!

👍 1
2025-08-13T12:48:57.891549Z

i know data readers are nice but maybe you could change your hiccup functions to use the fictions instead of readers?

seancorfield 2025-08-13T14:02:38.823179Z

@msolli Polylith lets you specify per-project pre- and post- test suite functions, precisely for this kind of global setup/teardown.

seancorfield 2025-08-13T14:03:27.774029Z

See https://cljdoc.org/d/polylith/clj-poly/0.2.23-SNAPSHOT/doc/configuration#ws-projects for :setup-fn and :teardown-fn

seancorfield 2025-08-13T14:04:07.784029Z

And here's part of our workspace.edn showing usage:

:test {:create-test-runner [org.corfield.external-test-runner.interface/create]}
 :projects {"development"       {:alias "dev"
                                  ;; since dev now runs admin tests, it needs the broadest
                                  ;; test setup/teardown, like wsadmin below:
                                 :test {:setup-fn    ws.admin.fixtures/pre-test
                                        :teardown-fn ws.admin.fixtures/post-test}}
            "build"             {:alias "b"}
            "activator"         {:alias "act"
                                 :test {:setup-fn    ws.application-fixtures.interface/pre-test
                                        :teardown-fn ws.application-fixtures.interface/post-test}}

seancorfield 2025-08-13T14:04:45.494269Z

(we're using a mix of clojure.test, expectations, and LazyTest with the external test runner)

msolli 2025-08-14T06:36:03.246489Z

Yes, this is exactly what I need! Didn't know about :setup-fn, it should do the trick. Thanks!