-
-
Notifications
You must be signed in to change notification settings - Fork 476
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow InModuleScope to not require the module to be loaded during discovery #1885
Comments
@JustinGrote I had the same idea, but it is quite complicated and the way InModuleScope works would have to change a lot. Leaving some edge cases I am not sure how to solve. Right now it uses the fact that scriptblock is tied to the session state that created it. So InModuleScope loads the module and then simply runs all the code inside of that module. This ties all the Describe and It, and all other stuff running in Discovery to the module, including TestCases. In effect all the scriptblocks that are attached to It block will run in the module scope on Run, because during discovery they were created inside of the module. If we were to avoid loading the module, we would have to take a note of the module name during Discovery, and then modify every scriptblock provided, to run inside of the module during Run. This still has at least three problems:
A completely different option is that we avoid the problem that caused not recommending InModuleScope outside of It in the first place, which was running tests after the whole discovery is done. This makes the scriptblocks to be bound to module session state that might no longer be the same (if you force import the module in some later discovery step) so your test and mocks will each run in a different session state, which come from the same module. Running discovery right before Run seems to be nice for parallel execution because that will always be split by file (otherwise there are some other serious problems). But the problem is that you don't know which describe is the last in the file, so you don't know when to execute Run in the file. Solving this problem would solve a lot of other problems. But before you suggest AST, then we can't really use that because Describe can be wrapped in whatever other function. |
@nohwnd Thanks for the notes. I can say the other place i use InModuleScope to mock commands in the module scope as the mocks don't work "normally". Example:
|
What if you do Mock -ModuleName Press ? |
I slap my hand to my forehead saying "I've done that before and for some reason forgot about it" |
Using -ModuleName parameter or simply testing by dot sourcing the functions directly instead of trying to do it inside module scope was my resolution for this issue. |
General summary of the issue
There are times when you only want the discovery phase (for instance, Tyler's Pester Text Explorer Extension) to determine the test structure. However, currently if you want to use InModuleScope, the module must be loaded during discovery, producing extra overhead especially in repeated test discovery scenarios. I don't see a strict reason this is necessary, and the check for module should be done later.
Describe your environment
Steps to reproduce
Expected Behavior
Module would not be tested if it is loaded until the actual test phase
Current Behavior
Pester fails at the discovery phase
Possible Solution? (optional)
Don't check the module is loaded until testing phase.
The text was updated successfully, but these errors were encountered: