• Announcement: Lua.org now officially recommends this forum as a meeting place for the Lua community

Not able to mock io library (1 Viewer)

devkapilbansal

Newcomer
Joined
May 10, 2021
Messages
2
Reaction score
0
Location
Delhi,India
Greetings Everyone,
I am trying to mock `io` library for testing. I make two tables definining package.loaded.io as some table.

The tables look like this:

TestNeighbor={
setUp=function()
local env=require('main_env')
package.loaded.io=env.io
end,
tearDown=function()
end
}

TestNetJSON={
setUp=function()
local env=require('basic_env')
package.loaded.io=env.io
end,
tearDown=function()
end
}

Then I use luaunit to tests some of the files. The problem I am facing is that the io defined in TestNeighbor is getting used by the TestNetJSON. I tried other ways too like setting package.loaded.io to nil etc. But, nothing seems to work.

What should I do in this case??
 
Last edited:
Top