1919import tempfile
2020import warnings
2121from pathlib import Path
22- from typing import List , Optional # noqa: F401 needed for typing.
22+ from typing import Dict , List , Optional # noqa: F401 needed for typing.
2323
2424from _pytest .config import Config as PytestConfig
2525from _pytest .config .argparsing import Parser as PytestParser
@@ -115,7 +115,7 @@ def pytest_configure(config: PytestConfig):
115115 setattr (config , "workflow_queue" , workflow_queue )
116116
117117 # Save which workflows are run and which are not.
118- executed_workflows = [] # type: List[ str]
118+ executed_workflows = {} # type: Dict[str, str]
119119 setattr (config , "executed_workflows" , executed_workflows )
120120
121121 # Save workflow for cleanup in this var.
@@ -191,7 +191,7 @@ def pytest_collection_modifyitems(config: PytestConfig,
191191 raise TypeError ("A workflow name should be defined in the "
192192 "workflow marker of {0}" .format (item .nodeid ))
193193
194- if workflow_name not in config .executed_workflows :
194+ if workflow_name not in config .executed_workflows . keys () :
195195 skip_marker = pytest .mark .skip (
196196 reason = "'{0}' has not run." .format (workflow_name ))
197197 item .add_marker (skip_marker )
@@ -204,6 +204,26 @@ def pytest_runtestloop(session: pytest.Session):
204204 )
205205
206206
207+ def pytest_collectstart (collector : pytest .Collector ):
208+ """This runs before the collector runs its collect attribute"""
209+
210+ if isinstance (collector , WorkflowTestsCollector ):
211+ name = collector .workflow_test .name # type: str
212+
213+ # Executed workflows contains workflow name as key and nodeid as value.
214+ executed_workflows = collector .config .executed_workflows # type: Dict[str,str] # noqa: E501
215+
216+ if name in executed_workflows .keys ():
217+ raise ValueError (
218+ "Workflow name '{this}' used more than once. Conflicting "
219+ "tests: {this_test}, {existing_test}. " .format (
220+ this = name ,
221+ this_test = collector .nodeid ,
222+ existing_test = executed_workflows [name ]
223+ )
224+ )
225+
226+
207227def pytest_sessionfinish (session : pytest .Session , exitstatus : int ):
208228 # No cleanup needed if we keep workflow directories
209229 # Or if there are no directories to cleanup. (I.e. pytest-workflow plugin
@@ -340,7 +360,10 @@ def collect(self):
340360 return []
341361 else :
342362 # If we run the workflow, save this for reference later.
343- self .config .executed_workflows .append (self .workflow_test .name )
363+ # Save the nodeid because it also contains the originating file.
364+ # This is useful for error messages later.
365+ self .config .executed_workflows [self .workflow_test .name ] = (
366+ self .nodeid )
344367
345368 # This creates a workflow that is queued for processing after the
346369 # collection phase.
0 commit comments