Pester のテストをしようとしているのですが、奇妙なエラー "A positional parameter cannot be found" (プライベート Python コマンドレットの場合) が表示されます。これは Pester の制限ですか、それとも以下のコードに何か問題がありますか?
TestModule.psm1コード:
#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 コード:
$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
}
}
}
テストコードを実行すると、次のエラーが発生します。
Create-Db テストの説明
コンテキスト データベースの作成
[-] Context ブロック 1.35 秒でエラーが発生しました
ParameterBindingException: 引数 '--DBMS SqlServer -d test_database' を受け入れる位置パラメーターが見つかりません。
Test-ParameterFilter で、C:\Program Files\WindowsPowerShell\Modules\Pester\3.3.14\Functions\Mock.ps1: 行 1086