Code

Opened 6 years ago

Closed 6 years ago

Last modified 3 years ago

#8047 closed (fixed)

admin_scripts tests doesn't work on Jython

Reported by: leosoto Owned by: jacob
Component: Testing framework Version: master
Severity: Keywords: jython
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

This set of tests rely on the PYTHONPATH environment variable to set the sys.path of the child python processes it launches and to read the potential location of external backends. But Jython doesn't use PYTHONPATH (nor does IronPython, for the record).

The attached patch fixes this by:

  • Tweaking the command line to be executed depending on the current platform.
  • Reading the "current PYTHONPATH" from sys.path instead of os.environ['PYTHONPATH'].

It also contains code to remove the compiled files generated from Jython, and avoids a check for the "pyc" extension on the output.

The only drawback I can see is that by using sys.path instead of PYTHONPATH, I've incremented the number places where a pre-existing 'settings.py' file would break the test. Practical example: a settings.py file under <django-root>/tests/.

If it is considered to be worth the effort, this patch could be improved by trying to point the the child's sys.path to only <django-root>, <django-root>/tests/regressiontests/ and <external-backend-root>.

Attachments (5)

8047_admin_scripts_tests_on_jython.diff (4.0 KB) - added by leosoto 6 years ago.
8047_admin_scripts_tests_on_jython.2.diff (3.8 KB) - added by leosoto 6 years ago.
8047_admin_scripts_tests_on_jython.3.diff (4.2 KB) - added by leosoto 6 years ago.
Avoid inheriting the whole sys.path, to the child processes. Now it just tries to detect the location of the external backend.
8047_admin_scripts_tests_on_jython.4.diff (2.6 KB) - added by leosoto 6 years ago.
updated to svn r8162
8047_admin_scripts_tests_on_jython.5.diff (2.4 KB) - added by leosoto 6 years ago.
I screwed up the patch the last time. Now it is ok

Download all attachments as: .zip

Change History (15)

Changed 6 years ago by leosoto

comment:1 Changed 6 years ago by leosoto

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

Crap, I just realized that the current patch will break the suite on windows where the commandline "PYTHONPATH=foo python" is very likely going to fail (don't have a windows box to confirm it right now).

comment:2 Changed 6 years ago by Alex

os.pathsep should contain the appropriate string for seperating paths in PYTHONPATH.

comment:3 Changed 6 years ago by leosoto

Well, I didn't explained well enough

With "PYTHONPATH=foo python" I tried to set the python path to foo and launch python in one shot. This way I didn't needed to mess with os.environ['PYTHONPATH'] and only _sys_executable had to deal with different Python VMs.

But it won't work on Windows, so I'm reverting that particular approach on this new patch.

Changed 6 years ago by leosoto

comment:4 Changed 6 years ago by russellm

(In [8158]) Refs #8047 -- Removed some CPython specific parts of the admin scripts tests.

comment:5 follow-up: Changed 6 years ago by russellm

The sys.path path of the proposed patch doesn't work for me; sys.path includes a lot of things that PYTHONPATH doesn't contain - in particular, the tests directory itself, which causes some of the tests to fail. Any other suggestions for composing PYTHONPATH?

comment:6 in reply to: ↑ 5 Changed 6 years ago by leosoto

Replying to russellm:

The sys.path path of the proposed patch doesn't work for me; sys.path includes a lot of things that PYTHONPATH doesn't contain - in particular, the tests directory itself, which causes some of the tests to fail.

Yeah, that was what I tried to explain on the last two paragraph of the ticket description. The new patch detect where the external backend is located and only adds its parent directory to the child's sys.path.

Changed 6 years ago by leosoto

Avoid inheriting the whole sys.path, to the child processes. Now it just tries to detect the location of the external backend.

comment:7 Changed 6 years ago by magneto

can i also suggest, while you're at it, to remove the 'Optimized' python bits "*.pyo"?

Changed 6 years ago by leosoto

updated to svn r8162

Changed 6 years ago by leosoto

I screwed up the patch the last time. Now it is ok

comment:8 Changed 6 years ago by ericholscher

  • Owner changed from nobody to jacob
  • Triage Stage changed from Unreviewed to Accepted

comment:9 Changed 6 years ago by jacob

  • Resolution set to fixed
  • Status changed from new to closed

(In [8238]) Fixed #8047: property detect an external database backend and set sys.path accordingly. Patch from Leo Soto.

comment:10 Changed 3 years ago by jacob

  • milestone 1.0 deleted

Milestone 1.0 deleted

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.