Bugfix: resolve StopIteration message attribute failure (#15341)
Testing the install StopIteration exception resulted in an attribute error: AttributeError: 'StopIteration' object has no attribute 'message' This PR adds a unit test and resolves that error.
This commit is contained in:
		 Massimiliano Culpo
					Massimiliano Culpo
				
			
				
					committed by
					
						 Todd Gamblin
						Todd Gamblin
					
				
			
			
				
	
			
			
			 Todd Gamblin
						Todd Gamblin
					
				
			
						parent
						
							733f9f8cfa
						
					
				
				
					commit
					59a7963785
				
			| @@ -1154,7 +1154,7 @@ def build_process(): | ||||
|         except StopIteration as e: | ||||
|             # A StopIteration exception means that do_install was asked to | ||||
|             # stop early from clients. | ||||
|             tty.msg('{0} {1}'.format(self.pid, e.message)) | ||||
|             tty.msg('{0} {1}'.format(self.pid, str(e))) | ||||
|             tty.msg('Package stage directory : {0}' | ||||
|                     .format(pkg.stage.source_path)) | ||||
| 
 | ||||
|   | ||||
| @@ -391,6 +391,27 @@ def test_install_task_use_cache(install_mockery, monkeypatch): | ||||
|     assert spec.package.name in installer.installed | ||||
| 
 | ||||
| 
 | ||||
| def test_install_task_stop_iter(install_mockery, monkeypatch, capfd): | ||||
|     """Test _install_task to cover the StopIteration exception.""" | ||||
|     mock_err_msg = 'mock stop iteration' | ||||
| 
 | ||||
|     def _raise(installer, pkg): | ||||
|         raise StopIteration(mock_err_msg) | ||||
| 
 | ||||
|     spec, installer = create_installer('a') | ||||
|     task = create_build_task(spec.package) | ||||
| 
 | ||||
|     monkeypatch.setattr(spack.package.PackageBase, 'unit_test_check', _true) | ||||
|     monkeypatch.setattr(inst.PackageInstaller, '_setup_install_dir', _raise) | ||||
| 
 | ||||
|     installer._install_task(task) | ||||
|     out = capfd.readouterr()[0] | ||||
| 
 | ||||
|     assert mock_err_msg in out | ||||
|     assert 'Package stage directory' in out | ||||
|     assert spec.package.stage.source_path in out | ||||
| 
 | ||||
| 
 | ||||
| def test_release_lock_write_n_exception(install_mockery, tmpdir, capsys): | ||||
|     """Test _release_lock for supposed write lock with exception.""" | ||||
|     spec, installer = create_installer('trivial-install-test-package') | ||||
|   | ||||
		Reference in New Issue
	
	Block a user