lein-ring icon indicating copy to clipboard operation
lein-ring copied to clipboard

0.8.3 runs all tests on reload

Open kornysietsma opened this issue 11 years ago • 17 comments

The 0.8.3 change seems to cause our tests to run whenever a reload happens.

i.e. If we run "lein ring server" the app loads happily (without running tests) If we then change a source file and refresh the browser, the server reloads and runs all our test code.

Reverting to 0.8.2 made this behaviour go away.

we have not set :reload-paths or changed our default :source-paths settings - our sources are in the "src" directory, tests are in "test" (and are Midje tests, btw)

kornysietsma avatar Mar 14 '13 06:03 kornysietsma

Same issue with 0.8.5

emil0r avatar May 10 '13 16:05 emil0r

Lein-Ring probably needs to be changed to ignore files in the test directories. Patches are welcome.

weavejester avatar May 10 '13 16:05 weavejester

ring.server itself defaults :reload-paths to ["src"]. But lein-ring overrides this.

"lein ring server" will automatically set :reload-paths if you have not. This currently defaults to monitoring everything on your classpath. In the near term (until test paths are filtered), if you want to prevent this set :reload-paths - "lein ring server" will honour this. Setting to ["src"] should bring back the behaviour from the previous version. (untested).

davesann avatar May 11 '13 08:05 davesann

If one were to attempt to patch this, what would you suggest as the correct solution?

noahlz avatar May 22 '13 15:05 noahlz

Have lein-ring exclude the project test paths from the reload-paths.

weavejester avatar May 22 '13 15:05 weavejester

Do you think such a change would impact any other users, i.e. is there a valid use case for including test sources in the reload path? For example, if you run a REPL in the server?

noahlz avatar May 22 '13 19:05 noahlz

It's probably not worth having by default. People can always override it with :reload-paths.

weavejester avatar May 22 '13 20:05 weavejester

This behavior changed from 0.8.2 -> 0.8.3, and it's a very surprising default: my entire test suite runs after modifying the ring app. @davesann, thank you for the workaround.

@noahlz, do you plan on submitting a pull request? If so, looking forward to it!

philc avatar May 25 '13 20:05 philc

I made the change that added the feature extending reloading paths beyond "src" in the parent project. I can probably fix this but there are some questions that need answers first.

The original change that I added built up the the source paths - this was changed in the final commit to use leiningen classpath - with unforeseen consequences. (a note though. I think it is probably bad practice for loading a file to runs tests directly)

The original change was here: https://github.com/davesann/lein-ring/commit/d65c2c44b1b8a784db99f73e18236328dfe68b83

I think it will be better to go back to building up the src directory list, rather than filter the classpath. I can't see how you can definitively test for a "test directory". (but we could choose to filter tests/*. This will not work in all cases).

Lein 1 and 2 projects may cause a problem because they use :source-path and :source-paths respectively.

Questions:

would you prefer to take the simple route and filter project-dir/tests/*?

if not, there are some choices in building the paths for reload:

  1. a. paths only from the immediate project checkouts (i.e don't recurse)? or; b. recurse all checkouts (i.e. checkouts under "checkout projects" all the way down) ?

    I believe lein only looks to the first level.

  2. a. lein2 :source-paths only? or; b. include lein2 :source-paths and lein1 :source-path as well if found?

  3. should any other paths be included for reload? resources?

  4. any other options?

Cheers Dave

davesann avatar Jun 24 '13 00:06 davesann

Take the simplest approach and just cut out the test paths.

Since it's customisable we don't need to think too hard about the defaults. We just need something that works in the majority of cases.

weavejester avatar Jun 24 '13 00:06 weavejester

It's been a while -- is this still an issue?

MichaelBlume avatar Jan 23 '15 06:01 MichaelBlume

This issue where test code is loaded still manifests unless you explicitly specify :reload-paths to just include your src dir. I ran into this with lein-ring 0.9.7.

acrao avatar Oct 08 '15 19:10 acrao

Ok, a few things. The tests just reload, right? I would not expect reloading them to also run them unless your tests are nonstandard. @philc are your tests actually running? Anyhow, I think I would expect tests and source to both reload? Is there anything wrong with just setting :reload-paths to ["src"] if you only want that?

MichaelBlume avatar Oct 11 '15 04:10 MichaelBlume

My recollection of Midje is that merely loading the test namespace also executes the tests. I don't know if this has been fixed, or if my recollection is wrong, but if it's still the case that would explain this behaviour.

If this is right, then there's not a lot we can do about it beyond allowing the reload-paths to be changed. To my mind this is a problem with Midje, as loading namespaces shouldn't incur side effects.

weavejester avatar Oct 11 '15 04:10 weavejester

Haha, this weird behaviour costed me 2hrs to debug 🙃 I had tests that emptied db tables and after each (non-test) code change I was left with empty tables – super confusing.

Setting {:ring {:reload-paths ["src"]}} seems to help; maybe defaults should be changed to that (instead of reloading all files)?

synthomat avatar Feb 14 '20 21:02 synthomat

If this is right, then there's not a lot we can do about it beyond allowing the reload-paths to be changed. To my mind this is a problem with Midje, as loading namespaces shouldn't incur side effects.

@weavejester You mean just declaring tests in a namespace should not execute any testing code unless you actually run the test suite? I faced this problem with midje too…

synthomat avatar Feb 14 '20 21:02 synthomat

You mean just declaring tests in a namespace should not execute any testing code unless you actually run the test suite?

Yes, that's right. Loading a namespace should be safe.

weavejester avatar Feb 15 '20 00:02 weavejester