I'm trying to do some Pester testing, and I get strange error "A positional parameter cannot be found" (for private Python cmdlet), is this a limitation of Pester or something is wrong with my code below?
TestModule.psm1
code:
#public function:
Function Create-Db
{
[CmdletBinding()]
Param(
[Parameter(Mandatory, ValueFromPipeline)]
[string]$database
)
Python 'Files\create_db.py' '--DBMS=SQLSERVER -d $database'
}
#private (not exported) function:
Function Python
{
[CmdletBinding()]
Param(
[Parameter(Mandatory, Position=1)]
[string]$scriptFile,
[Parameter(Position=2)]
[string]$args
)
$python ='C:\Python27\python.exe'
Push-Location $PSScriptRoot
$python = Start-Process -FilePath $python -ArgumentList @($scriptFile,$args) -Wait -NoNewWindow -PassThru
if($python.ExitCode -ne 0)
{
throw "Python script", $scriptFile, "failed"
}
Pop-Location
}
Pester code for the function:
$scriptDirectory = (Split-Path -Parent $MyInvocation.MyCommand.Path) -replace "Test$"
Import-Module $scriptDirectory\TestModule.psm1 -Force
Describe "Create-Db test" {
Context "Create database" {
Mock -ModuleName TestModule Python -Verifiable { return; }
Create-Db -database "test_database"
It "Python has been called" {
Assert-VerifiableMocks
}
}
}
When I execute the test code I get this error:
Describing Create-Db test Context Create database [-] Error occurred in Context block 1.35s ParameterBindingException: A positional parameter cannot be found that accepts argument '--DBMS SqlServer -d test_database'. at Test-ParameterFilter, C:\Program Files\WindowsPowerShell\Modules\Pester\3.3.14\Functions\Mock.ps1: line 1086