- 
          
 - 
                Notifications
    
You must be signed in to change notification settings  - Fork 2.9k
 
Some more config cleanups #13864
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Open
      
      
            bluetech
  wants to merge
  14
  commits into
  pytest-dev:main
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
bluetech:config-cleanups-2
  
      
      
   
  
    
  
  
  
 
  
      
    base: main
Could not load branches
            
              
  
    Branch not found: {{ refName }}
  
            
                
      Loading
              
            Could not load tags
            
            
              Nothing to show
            
              
  
            
                
      Loading
              
            Are you sure you want to change the base?
            Some commits from the old base branch may be removed from the timeline,
            and old review comments may become outdated.
          
          
                
     Open
            
            Some more config cleanups #13864
Conversation
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
    After parse, we should use the final `option` Namespace.
…preparse` The way our parser works, "unknown args" or only unknown *flags*. But `determine_setup` is not interested in those.
Can use the parse we did just before the call.
3f58da5    to
    7b779a1      
    Compare
  
    …rgs` Missed in fc2d649; we should be consistent here.
And a couple of minor cleanups.
7b779a1    to
    5ba2a24      
    Compare
  
    
              
                    nicoddemus
  
              
              approved these changes
              
                  
                    Nov 1, 2025 
                  
              
              
            
            
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed, everything LGTM. 👍
… parse Previously, `Parser` would create a new `ArgumentParser` for each parsing call (of which there are several during pytest initialization). Besides being a bit wasteful, it makes things hard to follow, especially since one `ArgumentParser` was saved on the `Parser` (in `optparser`). It makes a few refactorings I am planning difficult to pull off. So now, `Parser` instantiates one `ArgumentParser` in `__init__` and just adds groups/arguments to it immediately. There's more synchronization needed, but since arguments can only be added, never removed, it's not bad. One gotcha, in order to control `--help` group orders we must access argparse internals since it doesn't provide a way to do it. I checked and the relevant code hasn't changed since argparse was introduced 15 years ago. So hopefully it will continue to be fine.
The `after_preparse` hack was used to decide between two behaviors of `--help`: 1. Just set `help` on the Namespace and continue parsing 2. Interrupt the parsing The `after_preparse` was used to make 1 happen before `_preparse` and 2 after. But that's not what we want, the timing shouldn't really matter, only the "mode" in which we parse: - `Parser.parse_known_[and_unknown_]arguments` -- permissive mode, want behavior 1. - `Parser.parse` -- actual parsing, want behavior 2. Make it so.
Since this is not the first `getgroup` call on this name, the description is just ignored. It's also not really accurate, as the "general" group contains a bunch of stuff. So let's just keep "general" as the description for now.
No that "preparse" phase is no longer a thing, with the removal of the historic `pytest_cmdline_preparse` hook and `after_preparse` hack, let's inline so we can see the full parse flow in linear code.
5ba2a24    to
    2079b91      
    Compare
  
    
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
      
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Another batch of cleanups. This time there are a couple of more involved changes that remove a few hacks.