Registry entries and environment variables set in appveyor.yml not available in tests
Hi there,
In one of our project, an msi package needs to be installed before running our tests. The installation of the msi package creates registry entries that the tests relies upon to run. However, it seems that those entries are not available in the unit tests. Our tests are run by the automatic feature discovery from appveyor and are using nunit as a test engine.
I also tried to setup an environment variable from the appveyor.yml script but this variable is also not available in the tests.
The msi install is successful and is performed BEFORE the tests are run.
Any idea why the registry entries and /or the environment variables are not available from within the tests?
Any input on how to solve this issue?
Bests,
Michael
Comments are currently closed for this discussion. You can start a new one.
Keyboard shortcuts
Generic
? | Show this help |
---|---|
ESC | Blurs the current field |
Comment Form
r | Focus the comment reply box |
---|---|
^ + ↩ | Submit the comment |
You can use Command ⌘
instead of Control ^
on Mac
1 Posted by Ilya Finkelshte... on Jan 16, 2017 @ 11:35 PM
Hi Michael,
Could you please run Test-path against those registry paths after package installed and before tests run?
Also please send us how do you set environment variable and how is it being called from tests. If i is open source, just send us a links to respective part of
appveyor.yml
and test code.Thanks!
Ilya.
2 Posted by michael on Jan 17, 2017 @ 06:12 PM
Hi Ilya,
Well this is extremely weird. I spent quite some time today trying to
understand what was going on. The project is not open source yet but I
managed to reproduce the issue on one of my dummy projects that we use to
tests different features of appveyor
*The github project is *
https://github.com/sbsuite/ConsoleApp/tree/develop
I am running the same code to retrieve the variable from the registry in my
tests and from an executable called in the after_test hook.
https://github.com/sbsuite/ConsoleApp/blob/develop/tests/ConsoleApp.Tests/MainSpecs.cs#L37
AND
https://github.com/sbsuite/ConsoleApp/blob/develop/src/TestApp/Program.cs#L35
This is where the TestApp is called in the appveyor file
https://github.com/sbsuite/ConsoleApp/blob/develop/appveyor-bug.yml#L32
and here is the output
https://ci.appveyor.com/project/MichaelSevestre/consoleapp-lsyi2/build/0.4.2.5#L160
Now if I comment the test out, the after_test hook is called and the
TestApp program is called.
*This program can in turn READ from the registry*!! Here is the output
https://ci.appveyor.com/project/MichaelSevestre/consoleapp-lsyi2/build/0.4.2.7#L190
Any idea what's going on here?
THE CODE IS EXACTLY THE SAME between the TestApp and the Test.dll
Note that calling Test-Path does not work.
Test-Path -Path "HKEY_LOCAL_MACHINE:\SOFTWARE\BTS Products\MikTEX"
False
Test-Path -Path "HKEY_LOCAL_MACHINE:\SOFTWARE\BTS
Products\MikTEX\InstallDir"
False
Test-Path -Path "HKLM:\SOFTWARE\BTS Products\MikTEX"
False
Test-Path -Path "HKLM:\SOFTWARE\BTS Products\MikTEX\InstallDir"
False
event though the same key can be read from the TestApp on the line before.
I am not sure why but the doc also says that this is not something you can
really rely on
>Test-Path does not work correctly with all Windows PowerShell providers.
For example, you can use Test-Path to test the path of a registry key, but
if you use it to test the path of a registry entry, it always returns
$False, even if the registry entry is present.
To answer your second question, the way I defined the environment variable
(as a workaround) is
environment:
MIK_TEX_INSTALL_DIR: 'C:\MikTex\'
But the variable MIK_TEX_INSTALL_DIR is not available from
Environment.GetEnvironmentVariable(MIK_TEX_INSTALL_DIR). Is there another
way to access the Environment variable?
Last but not least, is there a way to ensure that the build script does not
stop if a test is failing?
Let me know if you have any questions and thanks for your help
Bests
Michael
3 Posted by Ilya Finkelshte... on Jan 18, 2017 @ 01:28 AM
OK, problem is that
msi
seems to update32-bit
registry keys. Probably TestProgram runs as 32-bit process and therefore sees that path. Butnunit
runner runs as 64-bit process and does not see this. I was able to make it pass either of one of 2 tricks:run test manually with command
nunit3-console.exe "C:\projects\consoleapp\tests\ConsoleApp.Tests\bin\Release\ConsoleApp.Tests.dll" --x86
. Note--x86
part (Run tests in an x86 process on 64 bit systems).change
_mikTEXRegistryPath
from@"HKEY_LOCAL_MACHINE\SOFTWARE\BTS Products\MikTEX"
to@"HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\BTS Products\MikTEX"
What about
Environment.GetEnvironmentVariable(MIK_TEX_INSTALL_DIR)
it should work, I just think that this should be string value and therefore surrounded with commas likeEnvironment.GetEnvironmentVariable("MIK_TEX_INSTALL_DIR")
. If this still does not work it would be great if you provide me with small repro in public repository like this one.Please let us know you are unblocked now.
Thanks!
Ilya.
4 Posted by michael on Jan 18, 2017 @ 02:17 AM
Hi Ilya,
Thanks so much for your quick feedback. I suspected indeed some weirdness
with 32-bit vs 64-bit.
The issue with the Environment variable is still not clear. You are right
it should be a string but this is was a constant defined as a string and I
just copied the line of code sorry
private const string MIK_TEX_INSTALL_DIR = "MIK_TEX_INSTALL_DIR";
I am going to try again with ENV Variable to ensure that I did not mess up
something.
Thanks so much for your help,
Bests,
Michael
Ilya Finkelshteyn closed this discussion on Aug 25, 2018 @ 02:14 AM.