ollien
I run my unit tests with mix test --no-start, as I don’t want my application to start when I run my unit tests. However, I also want to test some code that uses Timex for a calculation. If I naively attempt to use Timex in my test, I get the following
test "can get next instance of time in a trivial instance" do
next_occurrence =
Util.Time.get_next_occurrence_of_time(~D[2022-01-01], ~T[13:37:00], "America/New_York")
assert next_occurrence == Timex.to_datetime({{2022, 1, 1}, {13, 37, 0}}, "America/New_York")
end
1) test get_next_occurrence_of_time can get next instance of time in a trivial instance (PillminderTest.Util.Time)
test/pillminder/util/time_test.exs:8
** (ArgumentError) errors were found at the given arguments:
* 1st argument: the table identifier does not refer to an existing ETS table
code: assert next_occurrence == Timex.to_datetime({{2022, 1, 1}, {13, 37, 0}}, "America/New_York")
stacktrace:
(stdlib 3.17.2.1) :ets.lookup(:tzdata_current_release, :release_version)
(tzdata 1.1.1) lib/tzdata/release_reader.ex:74: Tzdata.ReleaseReader.current_release_from_table/0
(tzdata 1.1.1) lib/tzdata/release_reader.ex:17: Tzdata.ReleaseReader.simple_lookup/1
(tzdata 1.1.1) lib/tzdata/release_reader.ex:9: Tzdata.ReleaseReader.zone_and_link_list/0
(tzdata 1.1.1) lib/tzdata.ex:61: Tzdata.zone_exists?/1
(timex 3.7.9) lib/timezone/timezone.ex:230: Timex.Timezone.name_of/1
(timex 3.7.9) lib/timezone/timezone.ex:262: Timex.Timezone.get/2
(timex 3.7.9) lib/timezone/timezone.ex:585: Timex.Timezone.convert/2
(timex 3.7.9) lib/datetime/erlang.ex:46: Timex.Protocol.Tuple.to_datetime/2
test/pillminder/util/time_test.exs:12: (test)
I can understand why this might be; tzdata likely needs to be started in order to read from this ETS table. I’m not sure the best way to fix this, because
- If I remove
--no-start, my application will start, which has side effects I don’t want to produce just by running my unit tests. - Even if I somehow prevent my application from running (is there a way?), but allow Timex to run
tzdata, I’m still going to have side effects in my tests, Timex will need to update the timezone database before running my tests; I try to keep my unit tests free of network calls wherever I can.
How can I best deal with this? Is perhaps there some way I can “mock” the tzdata, or somehow pre-seed it for my unit tests?
Thanks!
Trending in Questions
Hi all,
I’m working on a Phoenix project where I need to make external HTTP requests and I’m trying to choose between Req and HTTPoison....
New
I’m very new to Elixir, so sorry if this is a silly question:
I am wondering what happens to the mailbox of a process when the machine i...
New
How do I tell Hologram not to escape HTML when substituting into templates?
{Textile.render(@product.long_description)}
escapes the HTM...
New
Background
When trying to execute mix release on a Windows 11 machine for a Phoenix project I get the following error:
* assembling mark...
New
I’d like to create a file with 600 permissions (rw-------), but there’s a race condition if I create it and then change the permissions. ...
New
Is there a way to import record definitions in the iex shell for pretty printing (similar to the rr command in the erl shell)? This woul...
New
When I use Mix.install with a git dependency, using git@github.com:... how do I change the SSH identity used?
I’ve got two Github accoun...
New
Other Trending Topics
Hey there,
I haven’t seen a list of useful Elixir specific skills for the popular AI tools yet so I’m starting one here with my first.
...
New
Hi everyone :waving_hand:
I wanted to share something I’ve been building — NowBlind, a random chat app designed to help people discover ...
New
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
(I just needed to vent somewhere and LinkedIn is full of hope, or hype, I’m not sure which exactly)
AI dream has many faces, but general...
New
Localize is the next generation localisation library for Elixir. Think of it as ex_cldr version 3.0. The first version will be released ...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #code-sync
- #discussion
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #ai
- #umbrella
- #elixirconf-us
- #full-time-contract
- #podcasts-by-brainlid
- #blog-post
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #elixirconf-eu
- #processes
- #security
- #api
- #forms
- #performance










Showing Posts 1 to 3- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
trisolaran
Hi @ollien and welcome!
You should be able to turn off tzdata automatic updates in your tests by setting:
in your
test.exsconfig (GitHub - lau/tzdata: tzdata for Elixir. Born from the Calendar library. · GitHub)Btw: you can now do time zone conversions directly in Elixir with the tzdata library without Timex: GitHub - lau/tzdata: tzdata for Elixir. Born from the Calendar library. · GitHub
Marcus
Welcome @ollien
You could try to start timex in your
test/test_helper.exswithApplication.ensure_all_started(:timex).ollien
Thanks for the suggestions! Looking at the tzdata docs it turns out you can also store the ets table locally, so I checked that into a testdata directory (originally in
./deps/tzdata/priv) and then added the following totest.exsand made added
Application.ensure_all_started(:tzdata)to my test setup.