Pester Testing for Module

Testing a large Powershell module with Pester 5.4.0, which is my first opportunity to leverage Pester. Many of the blogs were for older versions of Pester and version 5 is quite different in layout and scopes. This API has 300+ endpoints, so there are many tests. The tests are broken down by function (e.g. Tickets, Assets, Requesters, etc.), so there are Tickets.tests.ps1, Asset.tests.ps1 and Requesters.test.ps1 respectively.

Where do you Import the module? Where do you connect (sets global vars for the module)?

Import-Module Pester
Import-Module "$PSScriptRoot\..\PSFreshservice" -Force -ErrorAction Stop

Connect-Freshservice -Name ItsFine_Prod -NoBanner

Describe "SLA Policies" {

    InModuleScope PSFreshservice {
        BeforeDiscovery {
            $Script:guid = New-Guid
        }
        Context "View and List" {
            It "Get-FreshServiceSLAPolicy should return data" -Tag "SLA Policies" {
                $SLAs = Get-FreshServiceSLAPolicy
                $SLAs | Should -Not -BeNullOrEmpty
            }
        }
    }
}

I’ve had the first couple of lines in a BeforeAll{} block, but it doesn’t appear to execute or being scope for the Discovery as it tells me the module isn’t imported.

Also did it like this:

Describe "SLA Policies" {
    Import-Module Pester
    Import-Module "$PSScriptRoot/../PSFreshservice" -Force -ErrorAction Stop

    InModuleScope PSFreshservice {

        Connect-Freshservice -Name ItsFine_Prod
        BeforeDiscovery {
            $Script:guid = New-Guid
        }
        Context "View and List" {
            It "Get-FreshServiceSLAPolicy should return data" -Tag "SLA Policies" {
                $SLAs = Get-FreshServiceSLAPolicy
                $SLAs | Should -Not -BeNullOrEmpty
            }
        }
    }
}

Just getting some odd scoping issues where the Pester tests see a module or the variables aren’t populated. Just looking for guidance on how these should be setup. Logically, it would run those lines before Invoking Pester and then you aren’t doing it in every file. Thoughts? Guidance?